我在Woocommerce版本3+中创建了一个可变产品("父"产品).从Wordpress插件,我想以编程方式创建具有新属性值的产品变体("儿童"产品).
变体属性已在Woocommerce中设置.
因此,每次创建一个变体时,新属性的值也应该以编程方式创建,并在父变量产品中设置.
如何才能做到这一点?可能吗?
更新:我已经编写了更多我想要的代码行,并尝试了很多东西来解决它,使用woocommerce对象,并使用wordpress数据库在数据库中添加关于术语,termmeta,术语与post的关系的缺失数据对象 - 但没有什么能够让它发挥作用.我无法确定错误的地方 - 这就是为什么我无法提供更窄的问题 - 堆栈流更多的事情.
我想以编程方式创建一个带有两个新variante属性的变量产品("父"产品) - 所有这些都来自Wordpress插件(所以没有HTTP请求到API).
还应该动态创建这两个variante属性.
如何才能做到这一点 ?
(使用Woocommerce第3版)
更新:我已经写了更多代码,我希望,并尝试了很多东西来解决它,使用woocommerce对象,并使用wordpress数据库在数据库中添加关于术语,termmeta,术语与post的关系的缺失数据对象 - 但没有什么能够让它发挥作用.我无法确定错误的地方 - 这就是为什么我无法提供更窄的问题 - 堆栈流更多的事情.
我想用PHP代码以编程方式创建一个新的Woocommerce产品,并且已经使用Woocommerce 3 CRUD方法进行了尝试:
//Woocommerce CRUD
$objProduct = new WC_Product_Simple();
$objProduct->set_name('My Product 1'); //Set product name.
$objProduct->set_status('publish'); //Set product status.
//$objProduct->set_featured(FALSE); //Set if the product is featured. | bool
$objProduct->set_catalog_visibility('visible'); //Set catalog visibility. | string $visibility Options: 'hidden', 'visible', 'search' and 'catalog'.
$objProduct->set_description('My custom long description'); //Set product description.
//$objProduct->set_short_description('My short description'); //Set product short description.
//$objProduct->set_sku('U-123'); //Set SKU
$objProduct->set_price(5.00); //Set the product's active price.
//$objProduct->set_regular_price(5.00); //Set the product's regular price.
//$objProduct->set_sale_price(); //Set the product's sale price.
//$objProduct->set_date_on_sale_from(); //Set date on …Run Code Online (Sandbox Code Playgroud)