change product price in cart
-
To begin with I have a number of products that have an original price set in the administration end.
But then I also have a csv file that I’m reading from and if the products sku number matches a product in the file the price changes to whatever the csv file contains.
And that works fine but when the user add product to cart and goes to cart the price is still the original one. So i need help how to change the price globally.
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' ); function add_custom_price( $cart_object) { $custom_price = 17256; // This will be your custome price foreach ( $cart_object->cart_contents as $key => $value ) { $value['data']->price = $custom_price; } }
This function is easily found and it also does what it should as long as the custom_price is hardcoded. But whatever changes I make, as to adding another parameter and so on, fails for me. The custom_price should take whatever price the product has been given.
- The topic ‘change product price in cart’ is closed to new replies.