Woocommerce自定义结帐字段

时间:2015-01-22 10:53:42

标签: php wordpress woocommerce

我已经创建了一个自定义结帐字段,但我希望它能够与“运费/结算国家/地区”下拉列表动态做出反应。

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
global $woocommerce;
$ship_country = $woocommerce->customer->get_country();
    if ($ship_country !== 'US'){
    $fields['billing']['international_catalogue'] = array(
        'label'     => __('I would like to receive a catalogue', 'woocommerce'),
        'required'  => false,
        'type'      => 'checkbox',
        'class'     => array('my-field-class form-row-wide'),
        'default'   => 0
             );
         }
 $fields['billing']['email_opt_out'] = array(
    'label'     => __('Please send me the monthly newsletter <BR>(You can unsubscribe at any time)', 'woocommerce'),
    'required'  => false,
    'type'      => 'checkbox',
    'class'     => array('my-field-class form-row-wide'),
    'default'   => 1
         );

 return $fields;
}

如果您在更改国家/地区后重新加载结帐页面,这只会按我想要的方式运行。如何让此复选框动态反应?

0 个答案:

没有答案