【发布时间】:2015-10-28 05:44:51
【问题描述】:
我想创建一个插件,在选择运输方式时向 WooCommerce Checkout 添加一个自定义复选框。然后将此数据存储在自定义字段中并在电子邮件、管理员和感谢页面中打印出来。但不幸的是,结帐上的复选框没有出现:(
我的代码如下:
<?php
/**
* Plugin Name: GLS SMS Értesites
* Plugin URI: http://hu.linkedin.com/in/peterkulcsar/
* Description: GLS SMS Ertesites
* Version: 0.1
* Author: Peter Kulcsár - COOOL
* Author URI: http://hu.linkedin.com/in/peterkulcsar/
* 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>';
}
}
?>
感谢您的帮助。
【问题讨论】:
标签: php wordpress checkbox woocommerce