WooCommerce add product to cart with price override

woocommerce cart price override

some times we need to woocommerce change product price programmatically.

add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );

function add_custom_price( $cart_object ) {
$custom_price = 10; // This will be your custome price
foreach ( $cart_object->cart_contents as $key => $value ) {
$value['data']->price = $custom_price;
// for WooCommerce version 3+ use:
// $value['data']->set_price($custom_price);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*