I want to create a plugin, which adds a custom checkbox to WooCommerce Checkout, when a shipping method is selected. Then store this data in custom field and print it out in e-mail, admin and thank you page. But unfortunately the checkbox on Checkout doesn't appear :(
My Code is following:
<?php
/**
* Plugin Name: GLS SMS Értesites
* Plugin URI: http://ift.tt/1N9LHjg
* Description: GLS SMS Ertesites
* Version: 0.1
* Author: Peter Kulcsár - COOOL
* Author URI: http://ift.tt/1N9LHjg
* License: GPL
*/
if ( !defined( 'ABSPATH') ) exit;
add_action( 'woocommerce_review_order_before_payment',array( $this,'gls_sms_html'),1 );
add_action( 'woocommerce_checkout_update_order_meta',array( $this,'gls_sms_checkout_field_update_post') );
add_action( 'woocommerce_thankyou',array( $this,'gls_sms_thankyou_page') );
add_action( 'woocommerce_admin_order_data_after_shipping_address',array( $this,'gls_sms_show_selected_location_admin'),10,1 );
add_action( 'woocommerce_email_after_order_table',array( $this,'gls_sms_show_selected_location_admin'),10,1 );
function gls_sms_html($checkout)
{
global $woocommerce;
$chosen_methods = WC()->session->get( 'chosen_shipping_methods');
if ($chosen_methods[0] == 'table_rate_shipping'){
echo '<input type="hidden" name="gls_sms" value="0" />';
echo '<input type="checkbox" name="gls_sms" value="1" /><h3><i class="im-icon-mail-send"></i> SMS értesítés</h3>';
}
}
function gls_sms_checkout_field_update_post( $order_id )
{
if ( $_POST['gls_sms'] == '1')
update_post_meta( $order_id,'gls_sms',esc_attr( $_POST['gls_sms'] ) );
}
function gls_sms_thankyou_page( $order_id )
{
$gls_data = get_post_meta( $order_id,'gls_sms',true );
if ( $gls_data ) {
;echo '<h2>GLS SMS értesítés:</h2>
<p>Igen</p>';
}
}
function gls_sms_show_selected_location_admin( $order )
{
$gls_data = get_post_meta( $order->id,'gls_sms',true );
if ( $gls_data ) {
echo '<h4>GLS SMS értesítés:';
echo '</h4><p>';
echo 'Igen</p>';
}
}
?>
Thanks for help.
Aucun commentaire:
Enregistrer un commentaire