问题描述
如何通过代码为 woocommerce 属性添加值?我创建了一个名为调度时间"(分类:pa_dispatch)的属性,现在我想为特定产品的调度属性添加值.
How do I add value to a woocommerce attribute through code?I have created an attribute called 'Dispatch time' (taxonomy: pa_dispatch) and now I want to add value to a particular product's Dispatch attribute.
如何以编程方式执行此操作?
How to do this programmatically?
推荐答案
我找到了答案,你需要使用 wp_set_object_terms 设置分类对象的术语,
I found the answer, you need to use wp_set_object_terms to set the terms of object of a taxonomy,
wp_set_object_terms( $object_id, $terms, $taxonomy, $append);
其中,$append 可以是 true
或 false
,如果为真,标签将附加到现有标签,如果为假,标签被替换.
Where, $append can be true
or false
, if true, the tag will be appended to existing tag, if false, the tag is replaced.
在我的例子中,
wp_set_object_terms( $object_id, '2 Business Days', 'pa_dispatch' , false);
这里,pa_dispatch
是 woo-commerce 分类法.
Here, the pa_dispatch
is the woo-commerce taxonomy.
这篇关于woocommerce:为产品属性增加价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!