【发布时间】:2017-02-25 18:11:11
【问题描述】:
我已经对functions.php 中的这个简单函数了解得够多了,让我可以在优惠券中添加一个复选框。但是,一旦我保存/更新优惠券,我的复选框值(选中/未选中)不会被提交(因此复选框始终未选中)。换句话说,当我更新/保存时,我无法让它在 postmetas 的 meta_value 列中将值更新为 yes。复选框在那里,我只是不能使用它......非常令人沮丧!请对我做错的事情提出任何建议:)
function add_coupon_revenue_dropdown_checkbox() {
$post_id = $_GET['post'];
woocommerce_wp_checkbox( array( 'id' => 'include_stats', 'label' => __( 'Coupon check list', 'woocommerce' ), 'description' => sprintf( __( 'Includes the coupon in coupon check drop-down list', 'woocommerce' ) ) ) );
$include_stats = isset( $_POST['include_stats'] ) ? 'yes' : 'no';
update_post_meta( $post_id, 'include_stats', $include_stats );
do_action( 'woocommerce_coupon_options_save', $post_id );
}add_action( 'woocommerce_coupon_options', 'add_coupon_revenue_dropdown_checkbox', 10, 0 );
我想要影响的部分是:
wp-content/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php
【问题讨论】:
标签: php wordpress checkbox woocommerce hook-woocommerce