Jam*_*mes 5 php wordpress woocommerce
我正在尝试建立一个woocommerce商店,以便具有批发商或设计师角色的用户将自动免税,只需从购物车/结账中消税.我使用动态定价插件为不同的角色提供不同的价格,但税收变化没有选项.
有人发布了这段代码:
// Place the following code in your theme's functions.php file and replace tax_exempt_role with the name of the role to apply to
add_action( 'init', 'woocommerce_customer_tax_exempt' );
function woocommerce_customer_tax_exempt() {
global $woocommerce;
if ( is_user_logged_in() ) {
$tax_exempt = current_user_can( 'tax_exempt_role');
$woocommerce->customer->set_is_vat_exempt( $tax_exempt );
}
}
Run Code Online (Sandbox Code Playgroud)
这似乎是在前端工作但打破了后端.将它添加到functions.php后,当我回到管理区域并看到这个:http://i.imgur.com/nNHMSAZ.png(这只是新的Chrome错误页面吗?)
我无法弄清楚的另一件事是如何添加2个角色而不只是一个角色.
谢谢
小智 7
以下为我的用户角色"批发商"工作.添加到functions.php.
add_filter( 'woocommerce_before_checkout_billing_form', 'prevent_wholesaler_taxes' );
function prevent_wholesaler_taxes() {
global $woocommerce;
if( current_user_can('wholesaler')) {
$woocommerce->customer->set_is_vat_exempt(true);
} else {
$woocommerce->customer->set_is_vat_exempt(false);
}
} //end prevent_wholesaler_taxes
Run Code Online (Sandbox Code Playgroud)
要添加多个用户角色,只需添加到该current_user_can();功能即可.我认为这可行:
if( current_user_can('wholesaler')||current_user_can('another_user_role') )
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4111 次 |
| 最近记录: |