Update product variations prices in Woocommerce with WPDB query

假装没事ソ 提交于 2019-12-01 12:16:25

问题


I am using WordPress 4.7.4 and WooCommerce 3.0.5.

I updated _sale_price, _price, _regular_price using meta_id with code below:

   $meta_tbl = $wpdb->prefix.'postmeta';
   foreach ($_POST['loop'] as $loop_k => $loop_v) {
        $wpdb->update(
            $meta_tbl,
                array( 'meta_value' => $loop_v['price'] ),
                array( 'meta_id' => $loop_v['price_meta_id'] ),
                array( '%d' )
            );
        $wpdb->update(
            $meta_tbl,
                array( 'meta_value' => $loop_v['regular_price'] ),
                array( 'meta_id' => $loop_v['regular_price_meta_id'] ),
                array( '%d' )
            );
        $wpdb->update(
            $meta_tbl,
                array( 'meta_value' => $loop_v['sale_price'] ),
                array( 'meta_id' => $loop_v['sale_price_meta_id'] ),
                array( '%d' )
            );
  }

But still the shop page is displaying the old price of products! How can I do it properly?


回答1:


Try by adding this line after your code.

wc_delete_product_transients( $post_id );

// $post_id replace with product ID



来源:https://stackoverflow.com/questions/43805478/update-product-variations-prices-in-woocommerce-with-wpdb-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!