当我尝试以编程方式更新woocommerce产品属性时,它会在数据库中更新并显示在后端,但不会显示在网页的前端,代码如下:
wp_set_object_terms( $product_id, 'Thu 22 Mar 2018 | Fri 24 Mar 2018', 'Date', false );
$product_attributes['delivery-pickup-date'] = array(
'name' => 'Date',
'value' => 'Thu 22 Mar 2018 | Fri 24 Mar 2018',
'position' => 1,
'is_visible' => 1,
'is_variation' => 1,
'is_taxonomy' => 0
);
update_post_meta($product_id, '_product_attributes', $product_attributes);
WC_Product_Variable::sync($product_id);
我不知道我哪里出错了?任何帮助将不胜感激,谢谢!
答案 0 :(得分:0)
好的我自己可以修复它,代码中有错误,我需要替换以下代码:
$product_attributes['delivery-pickup-date'] = array(
'name' => 'Date',
'value' => 'Thu 22 Mar 2018 | Fri 24 Mar 2018',
'position' => 1,
'is_visible' => 1,
'is_variation' => 1,
'is_taxonomy' => 0
);
用这个:
$product_attributes['date'] = array(
'name' => 'Date',
'value' => 'Thu 22 Mar 2018 | Fri 24 Mar 2018',
'position' => 1,
'is_visible' => 1,
'is_variation' => 1,
'is_taxonomy' => 0
);
我的意思是将数组'delivery-pickup-date'的密钥替换为'date',以解决我的问题。