我需要从注册费中删除税,我无法看到对订阅征税的方式,而不是注册费。
我尝试过使用过滤器:woocommerce_subscriptions_product_price_string
。我只能设法打开或关闭注册费。
如何从注册费中删除税?
答案 0 :(得分:0)
这是正确使用的钩子,但要让它正常工作并不容易。因此,这是一个附加在 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文件中,或者放在任何插件文件中。
经过测试和工作。
但是在购物车项目中,注册费仍然是税收......但这是另一回事(或其他问题)......所以你需要找到改变它的方法......