您好,我正在尝试弄清楚如何根据所选的运输方式使用 woocommerce 结帐删除一些计费字段。因此,使用此代码,当客户选择本地送货时,我尝试取消设置帐单地址、帐单城市、帐单州和帐单邮政编码,但此代码不起作用。任何帮助,将不胜感激。
add_filter('woocommerce_checkout_fields', 'xa_remove_billing_checkout_fields');
function xa_remove_billing_checkout_fields($fields) {
$shipping_method ='local_pickup:1'; // Set the desired shipping method to hide the checkout field(s).
global $woocommerce;
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
if ($chosen_shipping == $shipping_method) {
unset($fields['billing']['billing_address_1']); // Add/change filed name to be hide
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_postcode']);
}
return $fields;
}
Run Code Online (Sandbox Code Playgroud)