隐藏 继续在Wordpress/WooCommerce中结帐



使用Wordpress和WooCommerce,我需要帮助添加两个用户角色。我得到了一个角色的工作,但也需要将其应用于另一个角色。

下面我使用的是用户角色"批发",但还有另一个用户角色需要将此规则应用于"us_wholesale"。

这是我在函数中的代码.php:

add_action( 'woocommerce_checkout_process', 'wdm_wu_minimum_order_amount' );
function wdm_wu_minimum_order_amount() {
$current_screen_user = wp_get_current_user();
if( in_array( 'wholesale', $current_screen_user->roles ) ) {
$minimum = 150;
if ( WC()->cart->subtotal < $minimum ) {
if( is_cart() ) {
wc_print_notice(
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->subtotal )
), 'error'
);
} else {
wc_add_notice(
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->subtotal )
), 'error'
);
} } } }

以及我在 wooCommerce 购物车总数中的覆盖.php:

<?php
$current_screen_user = wp_get_current_user();
if( in_array( 'wholesale', $current_screen_user->roles ) ) {
$minimum = 150; // Set the minimum amt.
$cart_amt = WC()->cart->subtotal; // cart sub_total, this is actual total excluding discounts and shipping.
if ( $cart_amt < $minimum ) {
if( is_cart() ) {
//Added notices for cart page.
wc_print_notice(
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( $cart_amt )
), 'error'
);
} else {
//Added notice msg for checkout page.
wc_add_notice(
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( $cart_amt)
), 'error'
);
}
} else {
do_action( 'woocommerce_proceed_to_checkout' );
}
} else {
do_action( 'woocommerce_proceed_to_checkout' );
}
?>

既然您只有两个要检查的角色,为什么不直接替换以下行:

if( in_array( 'wholesale', $current_screen_user->roles ) ) {

if( in_array( 'wholesale', $current_screen_user->roles ) || in_array( 'us_wholesale', $current_screen_user->roles ) ){

这样,如果当前用户具有wholesaleus_wholesale作为用户角色,则当前(可能正常工作?(函数将运行。

最新更新