我需要从注册费中扣除税款,我看不到对订阅而不是注册费征税的方法。
我试过使用过滤器:woocommerce_subscriptions_product_price_string. 我只能设法打开或关闭注册费。
如何从注册费中扣除税款?
我需要从注册费中扣除税款,我看不到对订阅而不是注册费征税的方法。
我试过使用过滤器:woocommerce_subscriptions_product_price_string. 我只能设法打开或关闭注册费。
如何从注册费中扣除税款?
这是使用正确的钩子,但要让它发挥作用并不容易。所以这里有一个自定义函数,woocommerce_subscriptions_product_price_string它会将显示的“含税”注册费价格替换为“不含税”的注册费价格。
我已经分离了一个可以重复使用的功能,即价格注册费。它将返回一系列价格(含/不含税的价格和含税的价格)。
这是该代码:
function get_price_sign_up_fee( $product ){
$price_incl_tax = wcs_get_price_including_tax( $product, array( 'price' => WC_Subscriptions_Product::get_sign_up_fee( $product ) ) );
$price_excl_tax = wcs_get_price_excluding_tax( $product, array( 'price' => WC_Subscriptions_Product::get_sign_up_fee( $product ) ) );
$price_tax = $price_incl_tax - $price_excl_tax;
return array( 'incl_tax' => $price_incl_tax, 'excl_tax' => $price_excl_tax, 'tax' => $price_tax );
}
add_filter( 'woocommerce_subscriptions_product_price_string', 'subscr_product_price_string', 10, 3 );
function subscr_product_price_string( $subscription_string, $product, $include ){
//print_pr($subscription_string);
if ( $include['sign_up_fee'] && WC_Subscriptions_Product::get_sign_up_fee( $product ) > 0 ) {
$sign_up_fee = get_price_sign_up_fee( $product );
// Replacing price to excluding taxes one
$subscription_string = str_replace( wc_price($sign_up_fee['incl_tax']), wc_price($sign_up_fee['excl_tax']), $subscription_string );
}
return $subscription_string;
}
代码在您的活动子主题(或主题)的 function.php 文件中或任何插件文件中。
测试和工作。
但是在购物车项目中,注册费仍然包含税款......但这是另一回事(或另一个问题)......所以你也需要找到对其进行更改的方法......