Set programmatically product sale price and cart item prices in Woocommerce 3

前端 未结 4 1871
走了就别回头了
走了就别回头了 2021-01-28 06:26

This is the continuation of : Set product sale price programmatically in WooCommerce 3

The answer works, however once a user adds the product to cart, the old price stil

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-28 07:26

    The accepted answer did not work for me. Here is what worked:

    function get_active_price($price, $product) {
            if ($product->is_on_sale()) {
                return $product->get_sale_price();
            }
            return $product->get_regular_price();
        }
    
    add_filter('woocommerce_product_get_price', 'get_active_price'));
    

    This worked with custom sale and regular prices.

提交回复
热议问题