Woocommerce - 使用 REST API 选择 "Single-Product-Variations" 插件选择器

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 语句更新它,但变体本身最终只是一个孤儿。

感谢任何帮助。 编辑: 我和插件的作者谈了一段时间,它似乎更新了任何东西,但标题并不像元那样简单。不仅如此。我正在努力弄清楚在哪里。他提到调用 "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

虽然这不是最优雅的解决方案,但我认为它很好地满足了我的目的。 我希望它对以后的其他人有所帮助。