第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

根據(jù)WooCommerce中的用戶角色更改數(shù)量步驟

根據(jù)WooCommerce中的用戶角色更改數(shù)量步驟

PHP
楊__羊羊 2021-05-06 18:17:24
在WooCommerce中,我嘗試根據(jù)用戶角色和產品來逐步更改“產品數(shù)量”字段設置。這是我的代碼add_filter( 'woocommerce_quantity_input_args', 'jk_woocommerce_quantity_input_args', 10, 2 ); // Simple productsfunction jk_woocommerce_quantity_input_args( $args, $product, $roles ) {    if ( is_singular( 'product' ) ) {        if( $product->get_id() == 85 ) {            $args['input_value'] = 30;        } else {            $args['input_value'] = 5;        }    }    if( array ( $roles, 'customer_roles')) {        $args['min_value']      = 1;         $args['step']           = 1;                   }    if( $product->get_id() == 85 ) {            $args['min_value'] = 30;            $args['step']      = 5;        } else {            $args['min_value'] = 5;            $args['step']      = 5;        }        return $args;}如何使此代碼也適用于用戶角色?
查看完整描述

1 回答

?
叮當貓咪

TA貢獻1776條經驗 獲得超12個贊

您的代碼$roles中存在一些錯誤,例如該鉤子參數(shù)不存在變量,還有一些其他錯誤……請嘗試以下操作:


add_filter( 'woocommerce_quantity_input_args', 'quantity_input_args_filter_callback', 10, 2 );

function quantity_input_args_filter_callback( $args, $product ) {

    // HERE define the user role:

    $user_role = 'customer_roles';


    $user = wp_get_current_user(); // Get the WP_Use Object


    // For a specific user role, we keep default woocommerce quantity settings

    if( in_array( $user_role, $user->roles ) ) 

        return $args; // Exit to default


    // For the others as following


    if ( is_singular( 'product' ) ) {

        if( $product->get_id() == 85 ) {

            $args['input_value'] = 30;

        } else {

            $args['input_value'] = 5;

        }

    }


    if( $product->get_id() == 85 ) {

        $args['min_value'] = 30;

        $args['step']      = 5;

    } else {

        $args['min_value'] = 5;

        $args['step']      = 5;

    }

    return $args;

}

代碼進入您的活動子主題(或活動主題)的function.php文件中。它應該工作。


查看完整回答
反對 回復 2021-05-14
  • 1 回答
  • 0 關注
  • 172 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號