Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 清除预先填写的装运字段值_Php_Wordpress_Woocommerce_Field_Checkout - Fatal编程技术网

Php 清除预先填写的装运字段值

Php 清除预先填写的装运字段值,php,wordpress,woocommerce,field,checkout,Php,Wordpress,Woocommerce,Field,Checkout,在wordpress客户下订单后,我需要从他们的个人资料中清除发货字段 这家商店是为销售礼品盒而设立的,许多回头客在每次回来时都会想把礼品盒寄到不同的送货地址。他们将使用与个人资料中相同的账单信息 add_filter('woocommerce_checkout_fields','custom_override_checkout_fields' ); function custom_override_checkout_fields( $fields ) { $fields['shippi

在wordpress客户下订单后,我需要从他们的个人资料中清除发货字段

这家商店是为销售礼品盒而设立的,许多回头客在每次回来时都会想把礼品盒寄到不同的送货地址。他们将使用与个人资料中相同的账单信息

add_filter('woocommerce_checkout_fields','custom_override_checkout_fields' );

function custom_override_checkout_fields( $fields ) {

  $fields['shipping']['shipping_first_name'] = '';
  $fields['shipping']['shipping_last_name'] = '';
  $fields['shipping']['shipping_company'] = '';
  $fields['shipping']['shipping_address_1'] = '';
  $fields['shipping']['shipping_address_2'] = '';
  $fields['shipping']['shipping_city'] = '';
  $fields['shipping']['shipping_postcode'] = '';
  $fields['shipping']['shipping_country'] = '';
  $fields['shipping']['shipping_state'] = '';

  return $fields;
}
这将清除字段,还将清除字段标签。我是否可以编辑现有的以仅清除字段,并使标签在每个字段上方可见


非常感谢您查看

您没有使用正确的过滤器挂钩…以下内容将清除预填充的装运字段值:

add_filter( 'woocommerce_checkout_get_value', 'clear_shipping_fields_values', 5, 2 );
function clear_shipping_fields_values( $value, $input ) {
    $keys = ['first_name','last_name','company','address_1','address_2','city','postcode','country','state'];
    $key  = str_replace('shipping_', '', $input);
    if( in_array($key, $keys) && is_checkout() ) {
        $value = '';
    }
    return $value;
}

代码进入活动子主题(或活动主题)的functions.php文件。经过测试,工作正常。

这真是太棒了,即使是“添加礼物邮件”这样的自定义发送字段也能正常工作。非常感谢您的帮助。