簡體   English   中英

Woocommerce-使用REST API選擇“單一產品變化”插件選擇器

[英]Woocommerce - Selecting “Single-Product-Variations” Plugin Selectors with REST API

我有一個woocommerce商店,該商店使用自定義上傳器從ChannelGrabber提取產品,並將其推到Woocommerce的過程比CG最初提供的更多細節。 客戶要求的一部分是讓每種顏色都顯示為單獨的變體 ,因此我安裝了一個名為“ Show Single Variations”的插件

通過其余的API,我能夠正確創建變體,並使用帶有所需標題的元鍵_jck_wssv_display_title 那太完美了。 不幸的是,如果我嘗試使用_jck_wssv_variable_show_search作為元鍵,則使用相同的邏輯,我無法使該復選框出現勾號。 我嘗試將值設置為1,是的,是的...我能想到的一切。

我99%確信這是正確的用法。

[
'key' => '_jck_wssv_variable_show_search',
'value' => true
],
[
'key' => '_jck_wssv_display_title',
'value' => $varMetaTitle
]

以前有沒有人對REST API和插件有好運? 我是不是很傻並且使用了錯誤的密鑰?

即使在創建變體之后,我仍嘗試使用put語句對其進行更新,但變體本身最終只是一個孤立的孤兒。

任何幫助表示贊賞。 編輯:我曾與插件的作者交談過一段時間,似乎在更新任何內容,但標題並不像meta一樣簡單。 不僅如此。 我正在努力去了解到底在哪里。 他提到了所謂的“ setter”方法..盡管我不確定在哪里看。

好吧,這需要一點腦力才能通過。 首先,您將要在wordpress目錄中的某個位置創建一個php文件。

基本前提是使用您需要的信息來CURL此文件。

我創建的文件大致如下所示:

<?php

if(!empty($_POST['id']) && !empty($_POST['check'])){

    $varID = $_POST['id']
    //take the id that will be sent in the curl request.

    require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php');
    //tell wordpress we need it to load, so we can reach the plugins.

    Iconic_WSSV_Product_Variation::set_visibility($varID, array("search", "catalog", "filtered"));
    //this calls the function set_visibility from the plugin.
    //it turns on the checkboxes i require for my variations
}
?>

設置文件后,我進入了腳本並在循環中添加了各種變體:

$ch = curl_init();
//initialise curl

$stringToCurl = "id=" . $getVar['id'] . "&check=yes";
//create string including id for this variant.
//i have an extra conditional for security here

curl_setopt($ch, CURLOPT_POSTFIELDS, $stringToCurl);
//set the curl options up

curl_setopt($ch, CURLOPT_URL, "https://www.example.co.uk/my_file.php");
//set the url to the path of the file

curl_exec($ch);
//execute the curl

雖然這不是最優雅的解決方案,但我認為它很好地滿足了我的目的。 我希望它對以后的其他人有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM