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

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

將用戶角色作為自定義元數(shù)據(jù)添加到WooCommerce訂單

將用戶角色作為自定義元數(shù)據(jù)添加到WooCommerce訂單

PHP
慕妹3146593 2021-04-29 13:14:32
在WooCommerce中,我想知道是否可以使用元鍵將用戶角色作為自定義字段保存到訂單(自定義元數(shù)據(jù))user_role,如以下屏幕截圖所示:
查看完整描述

1 回答

?
qq_遁去的一_1

TA貢獻1725條經(jīng)驗 獲得超8個贊

以下內(nèi)容將用戶角色添加為自定義訂單元數(shù)據(jù):


// Add the user roles as order meta data

add_action( 'woocommerce_checkout_create_order', 'add_user_roles_to_order_meta_data', 10, 2 );

function add_user_roles_to_order_meta_data( $order, $data ) {

    if( $order->get_user_id() > 0 ) {

        $user = $order->get_user();

        $user_role = reset($user->roles)


        $order->update_meta_data( 'user_role', $user_role );

    }

}

代碼進入您的活動子主題(或活動主題)的function.php文件中。經(jīng)過測試和工作。


要從WC_OrderObject$order變量獲取用戶角色,您將使用:


$user_role = $order->get_meta('user_role');

或從訂單ID$order_id變量中獲?。?/p>


$user_role = get_post_meta($order_id, 'user_role', true);


查看完整回答
反對 回復(fù) 2021-05-14
  • 1 回答
  • 0 關(guān)注
  • 143 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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