我对可变产品的更新价格有问题
update_post_meta( $post->ID, \'_regular_price\', (float)$meta_value );
update_post_meta( $post->ID, \'_price\', (float)$meta_value );
我将其用于产品ID和product\\u变体ID
我检查数据库。此字段已更新。
在商店和产品页面上显示旧价格。
但在购物车和结账时,我看到了最新的价格
if ($_POST[\'departments\']) {
//convert string to array
$vowels = array("[", "]", "\\"", "\\\\");
$departments = explode(",", str_replace($vowels, "", $_POST[\'departments\']));
update_post_meta( $post_id, \'departments\', $_POST[\'departments\'] );
foreach ($departments as $key => $value) {
$assign_product_id = explode(",", str_replace($vowels, "", $_POST[\'add_product_to_campaign\'][$key]));
$assign_product_price = explode(",", str_replace($vowels, "", $_POST[\'add_product_price_to_campaign\'][$key]));
foreach ($assign_product_id as $key_prod => $value_prod) {
$meta_value = trim($assign_product_price[$key_prod], \'\\\\\');
$product_id = trim($value_prod, \'\\\\\');
update_post_meta( $product_id, \'_regular_price\', $meta_value );
update_post_meta( $product_id, \'_price\', $meta_value );
$product_id = (int)$product_id;
global $wpdb;
$variable_post = $wpdb->get_results( \'SELECT ID FROM wp_posts WHERE post_parent = \' . $product_id);
if ($variable_post) {
foreach ($variable_post as $post) {
update_post_meta( $post->ID, \'_regular_price\', (float)$meta_value );
update_post_meta( $post->ID, \'_price\', (float)$meta_value );
}
}
}
}
} else {
delete_post_meta( $post_id, \'departments\' );
}