亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

手動設置 Coupon used_by Customer ID

手動設置 Coupon used_by Customer ID

PHP
倚天杖 2022-12-23 16:20:00
如果要通過 REST API 手動添加優惠券代碼或從管理員創建新訂單端點,我正在尋找有關在 Woocommerce 上設置優惠券 used_by particular customer user_id 的文檔。但我找不到正確的方法。希望有人能指點我。下面是我到目前為止開發的代碼,但它返回了 NULL。$WC_Coupon = new WC_Coupon($request['code']); $WC_Coupon->set_used_by( $request['customer_id'] );
查看完整描述

2 回答

?
飲歌長嘯

TA貢獻1951條經驗 獲得超3個贊

你確定你$WC_Coupon的實例化正確嗎?無論優惠券是如何添加到系統中的,一旦添加到系統中,它就應該像其他任何優惠券一樣起作用。

建議您獲取 $WC_Coupon 的 var_dump 并查看它是否輸出正確的值,否則,您可能沒有為構造函數提供正確的代碼參數。


查看完整回答
反對 回復 2022-12-23
?
小怪獸愛吃肉

TA貢獻1852條經驗 獲得超1個贊

如果我正確地解釋了代碼,您想要查找兩種貨幣的兩種產品。這可以在您定義產品和貨幣后使用嵌套的 foreach 循環來完成。


$cacheDirectory = $_SERVER['DOCUMENT_ROOT'] . '/cache/';

$url = 'https://remotedomain.com/?get=price';


const MAX_CACHE_TIME = 1600;


// Optional

$output = [];


$productList = [

    [

        'id'   => 10,

        'name' => 'SM',

    ],

    [

        'id'   => 20,

        'name' => 'LG',

    ]

];


$currencies = [

    'US' => 1,

    'EU' => 2,

];


foreach ($productList as $product) {

    foreach ($currencies as $currencyName => $currencyId) {

        $cacheFile = $cacheDirectory . $product['name'] . '_' . $currencyName . '.cache';


        if (!file_exists($cacheFile) || filemtime($cacheFile) > MAX_CACHE_TIME) {

            // No cache or too old

            $data = file_get_contents($url . '&product=' . $product['id'] . '&currency=' . $currencyId);

            $relevantData = substr($data, 17, 2);

            file_put_contents($cacheFile, $relevantData);

            // Optional, put the data in an array

            $output[$product['id']][$currencyId] = $relevantData;

        } else {

            $output[$product['id']][$currencyId] = file_get_contents($cacheFile);

        }


    }

}


// Read output with $output[10]['US'] for example

分享

編輯

跟隨


查看完整回答
反對 回復 2022-12-23
  • 2 回答
  • 0 關注
  • 187 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號