Woocommerce 从不在结帐页面上保存送货地址
Woocommerce never save shipping address on checkout page
默认情况下,Woocommerce 会在结帐页面上保存账单地址和送货地址。
我正在寻找一种方法来防止 Woocommerce 保存送货地址中的值。因此 送货地址 中的所有字段都应为空。
在中我找到了部分解决方案。效果很好,但也会使帐单地址为空:
add_filter('woocommerce_checkout_get_value','__return_empty_string',10);
有没有办法只针对送货地址执行此操作?
非常感谢!
您可以像这样更改代码...
add_filter( 'woocommerce_checkout_get_value', 'reigel_empty_checkout_shipping_fields', 10, 2 );
function reigel_empty_checkout_shipping_fields( $value, $input ) {
/*
Method 1
you can check the field if it has 'shipping_' on it...
if ( strpos( $input, 'shipping_' ) !== FALSE ) {
$value = '';
}
Method 2
put all the fields you want in an array...
*/
$shipping_fields = array(
//'shipping_first_name',
//'shipping_last_name',
'shipping_company',
'shipping_country',
'shipping_address_1',
'shipping_address_2',
'shipping_city',
'shipping_state',
'shipping_country',
'shipping_postcode'
);
if ( in_array( $input, $shipping_fields ) ) {
$value = '';
}
return $value;
}
默认情况下,Woocommerce 会在结帐页面上保存账单地址和送货地址。
我正在寻找一种方法来防止 Woocommerce 保存送货地址中的值。因此 送货地址 中的所有字段都应为空。
在
add_filter('woocommerce_checkout_get_value','__return_empty_string',10);
有没有办法只针对送货地址执行此操作?
非常感谢!
您可以像这样更改代码...
add_filter( 'woocommerce_checkout_get_value', 'reigel_empty_checkout_shipping_fields', 10, 2 );
function reigel_empty_checkout_shipping_fields( $value, $input ) {
/*
Method 1
you can check the field if it has 'shipping_' on it...
if ( strpos( $input, 'shipping_' ) !== FALSE ) {
$value = '';
}
Method 2
put all the fields you want in an array...
*/
$shipping_fields = array(
//'shipping_first_name',
//'shipping_last_name',
'shipping_company',
'shipping_country',
'shipping_address_1',
'shipping_address_2',
'shipping_city',
'shipping_state',
'shipping_country',
'shipping_postcode'
);
if ( in_array( $input, $shipping_fields ) ) {
$value = '';
}
return $value;
}