【发布时间】:2020-08-21 06:02:42
【问题描述】:
我想在 woocommerce 中以编程方式应用属性,因为我使用了此代码,但它不起作用,任何人都可以查看我的代码并帮助我解决此问题吗?
$product_id = 4931;
$attribute_name = "test_attribute";
$attribute_value = "test_attribute";
$term_taxonomy_ids = wp_set_object_terms($product_id, $attribute_value, $attribute_name, true);
$data = array(
$attribute_name => array(
'name' => $attribute_name,
'value' => '',
'is_visible' => '1',
'is_variation' => '0',
'is_taxonomy' => '1'
)
);
//First getting the Post Meta
$_product_attributes = get_post_meta($product_id, '_product_attributes', TRUE);
//Updating the Post Meta
update_post_meta($product_id, '_product_attributes', array_merge($_product_attributes, $data));
}
【问题讨论】:
标签: wordpress woocommerce