Woo-Commerce change product price in cart


/*Update below code in functions.php it will change cart page and checkout page*/

add_action( ‘woocommerce_before_calculate_totals’, ‘add_custom_price’ );
function add_custom_price( $cart_object ) {
$custom_price = 0.0;

foreach ( $cart_object->cart_contents as $value ) {
if ( $value[‘product_id’] == $free_id ) {

//Woo-Commerce version below 2.7.0
$value[‘data’]->price = $custom_price;

//Woo-Commerce version above 3.0.0
$value[‘data’]->set_price($custom_price);
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s