我正在尝试隐藏基于送货方式的结帐字段.
function premove_billing_checkout_fields($fields) {
global $woocommerce;
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
if( $chosen_shipping === 'local_pickup:20' ) {
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_country']);
}
if( $chosen_shipping === 'wc_custom_shipping_pickpoint' ) {
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_state']);
}
return $fields;
}
add_filter('woocommerce_checkout_fields',
'premove_billing_checkout_fields', 990 );
Run Code Online (Sandbox Code Playgroud)
此代码正常工作,但要隐藏刷新页面所需的字段.如何使用Ajax隐藏字段?
在 WooCommerce 中,每当选择“送货到家”时,我都会尝试隐藏公司名称字段。我尝试过很多不同的事情。
这是我最近的尝试:
add_filter('woocommerce_checkout_fields', 'xa_remove_billing_checkout_fields');
function xa_remove_billing_checkout_fields($fields) {
$shipping_method ='pakkelabels_shipping_gls1'; // 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_company']); // Add/change filed name to be hide
}
return $fields;
}
Run Code Online (Sandbox Code Playgroud)
但它所做的只是将航运公司从第一个字段移至最后一个字段。
如何根据所选的送货方式有条件地隐藏特定的结账字段?