【发布时间】:2019-07-20 10:01:32
【问题描述】:
我有一个 php 代码,它在网站范围内设置了 100 个最小订单,效果很好。
我想使用相同的代码或通过克隆它并将其包装在 if() 语句中为特定角色“公司”设置不同的最小订单 250,只是我不知道如何编写它。将不胜感激任何形式的帮助。
这是醋栗代码(不要介意希伯来语文本,它只是错误消息,当条件不满足时):
// Set a minimum dollar amount per order
add_action( 'woocommerce_check_cart_items', 'spyr_set_min_total' );
function spyr_set_min_total() {
// Only run in the Cart or Checkout pages
if( is_cart() || is_checkout() ) {
global $woocommerce;
// Set minimum cart total
$minimum_cart_total = 100;
// Total we are going to be using for the Math
// This is before taxes and shipping charges
$total = WC()->cart->subtotal;
// Compare values and add an error is Cart's total
// happens to be less than the minimum required before checking out.
// Will display a message along the lines of
// A Minimum of 10 USD is required before checking out. (Cont. below)
// Current cart total: 6 USD
if( $total <= $minimum_cart_total ) {
// Display our error message
wc_add_notice( sprintf( '<strong>לקוח יקר, יש צורך במינימום הזמנה
של %s %s₪ על מנת לבצע רכישה באתר.</strong>'
.'<br />סכום הביניים בעגלה הינו: %s %s₪',
$minimum_cart_total,
get_option( 'woocommerce_currency_symbol'),
$total,
get_option( 'woocommerce_currency_symbol') ),
'error' );
}
}
}
谢谢!
【问题讨论】:
标签: php wordpress woocommerce cart user-roles