我需要获取所有变体ID并在循环中更新价格.简单的查询和循环看起来像:
$params = array(
‘posts_per_page’ => -1,
‘post_type’ => ‘product_variation’,
‘post_parent’ => $product->get_id() // tried $post-ID
);
$variations = get_posts( $params );
foreach ( $variations as $variation ) {
$variation_ID = $variation->ID; // tried $post-ID, $product->get_id()
$regular_price=34;
update_post_meta( $variation_ID, ‘_regular_price’, (float)$regular_price );
update_post_meta( $variation_ID, ‘_price’, (float)$regular_price );
}
Run Code Online (Sandbox Code Playgroud)
我认为不这样做:
(‘post_parent’ => $product->get_id())
Run Code Online (Sandbox Code Playgroud)
或这个:
($variation_ID = $variation->ID;).
Run Code Online (Sandbox Code Playgroud)