首页 文章

Woocommerce永远不会在结帐页面保存送货地址

提问于
浏览
2

默认情况下,Woocommerce会在结帐页面上保存结算和送货地址 .

我正在寻找一种方法来阻止Woocommerce保存送货地址中的值 . 因此 shipping address 中的所有字段都应为空 .

another thread我找到了部分解决方案 . 它工作得很好,但它也使得帐单地址为空:

add_filter('woocommerce_checkout_get_value','__return_empty_string',10);

有没有办法只为送货地址这样做?

大thx!

1 回答

  • 2

    您可以像这样更改代码......

    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;
    }
    

相关问题