我需要以编程方式更新可变产品及其所有变体的销售价格。
我需要添加什么样的元字段?
我正在尝试更新主要产品,例如:
update_post_meta($post_id, '_regular_price', '100');
update_post_meta($post_id, '_price', '50');
update_post_meta($post_id, '_sale_price', '50');
然后我更新每一个变体
update_post_meta($variation_id, '_regular_price', '100');
update_post_meta($variation_id, '_price', '50');
update_post_meta($variation_id, '_sale_price', '50');
update_post_meta($variation_id, 'attribute_pa_taglia', $term_slug);
update_post_meta($variation_id, '_stock', $stock);
update_post_meta($variation_id, '_stock_status', 'instock');
update_post_meta($variation_id, '_manage_stock', 'yes');
但是后端(产品列表)和前端给我旧的价格
最佳答案
此外,我还找到了其他效果相同的解决方案:
$product_variable = new WC_Product_Variable($post_id);
$product_variable->sync($post_id);
wc_delete_product_transients($post_id);
关于php - 以编程方式将销售价格添加到产品变体中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41547590/