Php 为特定用户角色设置最低订单

Php 为特定用户角色设置最低订单,php,wordpress,woocommerce,cart,user-roles,Php,Wordpress,Woocommerce,Cart,User Roles,我有一个php代码,它在整个站点范围内设置了100个最小订单,效果很好。 我想使用相同的代码,或者通过克隆特定角色“company”并将其包装到if()语句中,为其设置不同的最小顺序250,只是我不知道如何编写它。非常感谢您的帮助。 这是current代码(不要介意希伯来文,当条件不满足时,这只是错误消息): //设置每个订单的最低美元金额 添加操作('woocommerce\u check\u cart\u items'、'spyr\u set\u min\u total'); 函数spyr\

我有一个php代码,它在整个站点范围内设置了100个最小订单,效果很好。 我想使用相同的代码,或者通过克隆特定角色“company”并将其包装到if()语句中,为其设置不同的最小顺序250,只是我不知道如何编写它。非常感谢您的帮助。
这是current代码(不要介意希伯来文,当条件不满足时,这只是错误消息):

//设置每个订单的最低美元金额
添加操作('woocommerce\u check\u cart\u items'、'spyr\u set\u min\u total');
函数spyr\u set\u min\u total(){
//仅在购物车或结帐页面中运行
if(is_cart()| | is_checkout()){
全球商业;
//设置最小购物车总数
$minimum_cart_total=100;
//我们将用于数学的总数
//这是税前和运费
$total=WC()->购物车->小计;
//比较值并添加一个错误是购物车的总数
//恰好低于退房前的最低要求。
//将沿以下行显示消息:
//退房前至少需要10美元(续)
//当前购物车总计:6美元

如果($total,则必须首先检索当前用户的角色

$roles = is_user_logged_in() ? (array) wp_get_current_user()->roles : [];
现在,您需要检查角色
公司
是否在用户角色中,以确定最小值

$minimum_cart_total = in_array('company', $roles) ? 250 : 100;

使用
当前用户\u can()
尝试以下操作,以便在代码中:

// Set a minimum amount per order (and user role)
add_action( 'woocommerce_check_cart_items', 'set_min_total_per_user_role' );
function set_min_total_per_user_role() {
    // Only run in the Cart or Checkout pages
    if( is_cart() || is_checkout() ) {

        // Set minimum cart total
        $minimum_cart_total = current_user_can('company') ? 250 : 100;

        // Total (before taxes and shipping charges)
        $total = WC()->cart->subtotal;

        // Add an error notice is cart total is less than the minimum required
        if( $total <= $minimum_cart_total  ) {
            // Display our error message
            wc_add_notice( sprintf( '<strong>Dear customer, minimum order of %s is required to make a purchase on your site.</strong> <br>
                Your actual cart amount is: %s',
                wc_price($minimum_cart_total),
                wc_price($total)
            ), 'error' );
        }
    }
}
//设置每个订单(和用户角色)的最低金额
添加操作('woocommerce\u check\u cart\u items'、'set\u min\u total\u per\u user\u role');
函数集\最小\总计\每个用户\角色(){
//仅在购物车或结帐页面中运行
if(is_cart()| | is_checkout()){
//设置最小购物车总数
$minimum_cart_total=当前用户_can(“公司”)?250:100;
//总计(税前和运费前)
$total=WC()->购物车->小计;
//如果购物车总数小于所需的最小值,则添加错误通知

如果($total,谢谢!我在网上得到一个错误:wc\U价格($minimum\u cart\u total),@fafchook这是因为希伯来文字符…我已经用英文替换了,它工作起来…好吧,这很奇怪。因为它在以前的代码中工作得很好。你知道有没有办法翻译它吗?可能是通过PO文件?明白了。出于某种原因,用希伯来文字符复制代码会产生错误,但粘贴后修改它不会。比再一次,我的朋友,你是一个救生员!@fafchook只需用希伯来语输入所需字符串,然后添加
%s
,其中需要有格式化的“最低购物车价格”和格式化的“总计”。然后您可以在其中添加html标记

。。我自己做不到,因为我不懂希伯来语,而且它是RTL语言。
// Set a minimum amount per order (and user role)
add_action( 'woocommerce_check_cart_items', 'set_min_total_per_user_role' );
function set_min_total_per_user_role() {
    // Only run in the Cart or Checkout pages
    if( is_cart() || is_checkout() ) {

        // Set minimum cart total
        $minimum_cart_total = current_user_can('company') ? 250 : 100;

        // Total (before taxes and shipping charges)
        $total = WC()->cart->subtotal;

        // Add an error notice is cart total is less than the minimum required
        if( $total <= $minimum_cart_total  ) {
            // Display our error message
            wc_add_notice( sprintf( '<strong>Dear customer, minimum order of %s is required to make a purchase on your site.</strong> <br>
                Your actual cart amount is: %s',
                wc_price($minimum_cart_total),
                wc_price($total)
            ), 'error' );
        }
    }
}