wordpress 更改woocommerce默认纳税国家/地区位置

1zmg4dgp  于 2023-03-22  发布在  WordPress
关注(0)|答案(1)|浏览(240)

WooCommerce只允许根据账单/送货地址和商店基地(和地理位置)计算税收,但是我想为尚未选择国家的新访问者手动设置默认税收位置,到一个静态国家,而不改变基地商店地址。
我不想改变基地店地址的原因是,因为我相信这可能会影响插件使用它来显示一个基地地址,这将不再是正确的,因为这个税收国家的位置。
我试着用钩子;

add_filter( 'woocommerce_get_tax_location', 'customer_default_tax_location', 20, 3 );
function customer_default_tax_location( $location, $tax_class = '', $customer = null ) {
    if ( ! is_null( $customer ) && is_null( $customer->get_shipping_country() ) && is_null( $customer->get_billing_country() ) ) {
        return ['NL', null, '', ''];
    }
    return $location;
}

add_filter( 'woocommerce_customer_default_location', 'customer_default_location', 10, 1 );
function customer_default_location( $location ) {
    return "NL";
}

但是这会带来一个问题,因为$customer-〉get_shipping_country/get_billing_country()总是会返回一个国家,即使访问者还没有创建一个会话,所以这不会起作用。有没有办法检查客户是否还没有在购物车或结账(或登录)时指定或选择一个国家?

0yycz8jy

0yycz8jy1#

$customer已经不是null了,因为get_tax_location()已经检查过了。
© 2019 www.woocommerce.com版权所有并保留所有权利

function bbloomer_customer_default_tax_location( $location, $tax_class, $customer ) {
    if ( ! $customer->get_shipping_country() && ! $customer->get_billing_country() ) {
        return array( 'NL', '', '', '' );
    }
    return $location;
}

相关问题