我正在寻找一种方法来为 WooCommerce 中的特定用户角色添加额外的购物车/税费。我正在使用WooCommerce PDF 发票和装箱单插件。至少应将此费用添加到发送给用户的电子邮件和随它一起发送的 PDF 发票中。
我看了下面的代码,并认为我可以使用它。我只是不明白如何为产品添加不同的“税级”。所以现在发生的事情是根本没有加税。
add_filter( 'woocommerce_before_cart_contents', 'wc_diff_rate_for_user', 1, 2 );
add_filter( 'woocommerce_before_shipping_calculator', 'wc_diff_rate_for_user', 1, 2);
add_filter( 'woocommerce_before_checkout_billing_form', 'wc_diff_rate_for_user', 1, 2 );
add_filter( 'woocommerce_product_tax_class', 'wc_diff_rate_for_user', 1, 2 );
function wc_diff_rate_for_user( $tax_class ) {
if ( !is_user_logged_in() || current_user_can( 'customer' ) ) {
$tax_class = 'Zero Rate';
}
return $tax_class;
}
我希望任何人都可以帮助我。