如果选择本地取件,我不想要billing_last_name
。
尝试这样的事情:
function xa_remove_billing_checkout_fields($fields) {
$shipping_method ='local_pickup'; // 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) {
$fields['billing']['billing_last_name'][ 'required' ] = false;
}
return $fields;
}
但它不起作用。
有适当的解决方案吗?
答案 0 :(得分:2)
这是您使用钩子更新的代码:
add_filter('woocommerce_checkout_fields', 'xa_remove_billing_checkout_fields');
function xa_remove_billing_checkout_fields($fields) {
$shipping_method ='local_pickup'; // 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) {
$fields['billing']['billing_last_name'][ 'required' ] = false;
}
return $fields;
}