在WooCommerce中,我正在尝试隐藏一个自定义添加的字段,每当“免费送货”被选择时(自动选择,基于订单金额)。
我认为下面的代码可以解决问题,但是当我在新的(隐身)浏览器窗口上加载页面时,该字段存在,如果刷新它,则该字段再次隐藏。
我认为下面的代码可以解决问题,但是当我在新的(隐身)浏览器窗口上加载页面时,该字段存在,如果刷新它,则该字段再次隐藏。
// Hide address field, when Free Shipping mode is selected
add_filter('woocommerce_checkout_fields', 'xa_remove_billing_checkout_fields');
function xa_remove_billing_checkout_fields($fields) {
$shipping_method ='free_shipping:5'; // 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_field_432']); // Add/change filed name to be hide
}
return $fields;
}
非常感谢您的帮助。