Get the product object from sku and update the price in WooCommerce
问题 How can I update a product by product_id in my functions file? I tried using the below code but to no success: $_pf = new WC_Product_Factory(); $product_id = wc_get_product_id_by_sku( $sku ); $_product = $_pf->get_product($product_id); $_product->set_price('225'); 回答1: Since WooCommerce 3, new WC_Product_Factory() with get_product() method is deprecated and replaced simply by the function wc_get_product() . To update price, you have to update the price and the regular price (or the price and