【发布时间】:2018-10-11 06:35:07
【问题描述】:
在 woocommerce 中,如果满足两个条件,我目前正在寻求在我的主题的 functions.php 文件中添加一个函数。然后,使用elseif(),只要满足一个条件就部署函数。
代码如下:
add_action( 'woocommerce_widget_shopping_cart_before_buttons' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
$minimum = 150;
$minimum2 = 100;
if ( is_page([232]) && WC()->cart->subtotal < $minimum2 ) {
if( 'woocommerce_widget_shopping_cart' ) {
wc_print_notice(
sprintf( 'Your current order total does not meet the %s minimum' ,
wc_price( $minimum2 )
), 'error'
);
remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_proceed_to_checkout', 20 );
}
else {
wc_add_notice(
sprintf( 'Your current order total does not meet the %s minimum' ,
wc_price( $minimum2 )
), 'error'
);
}
}
elseif ( WC()->cart->subtotal < $minimum ) {
if( 'woocommerce_widget_shopping_cart' ) {
wc_print_notice(
sprintf( 'Your current order total does not meet the %s minimum',
wc_price( $minimum )
), 'error'
);
remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_proceed_to_checkout', 20 );
}
else {
wc_add_notice(
sprintf( 'Your current order total does not meet the %s minimum' ,
wc_price( $minimum )
), 'error'
);
}
}
}
如果未达到最低订单金额,我要做的是隐藏 woocommerce 小部件的结帐按钮。但是,不同的页面有不同的最小值。
如果购物车不等于 150 美元,我会尝试隐藏结帐按钮。但特别是对于一页,我只希望购物车至少有 100 美元。
【问题讨论】:
-
我可以看到的主要问题(没有测试,因为我现在不在我的办公桌前)是
if( 'woocommerce_widget_shopping_cart' ) {- 你实际上并没有在你的 if 语句中测试任何东西。您正在测试字符串“woocommerce_widget_shopping_cart”怎么样?它应该等于或不等于?
标签: php wordpress if-statement woocommerce cart