vendredi 2 janvier 2015

Woocommerce custom price returns zero in checkout page


I need to allow the user to enter the price for particular product to purchase.For this I just added a input field for entering price for that particular product and write the following code in the function.



add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );

function add_custom_price( $cart_object ) {
$custom_price = $_POST['price'];
$target_product_id = 229;
foreach ( $cart_object->cart_contents as $key => $value ) {
if ($value['product_id'] == $target_product_id ) {
$value['data']->price = $custom_price;
}

}
}


And it works fine in the cart page.But when adding another products to the cart or going to the checkout page that product price changes to zero.Why this happens?.Is there any additional settings needed for overriding the price. Please help asap





Aucun commentaire:

Enregistrer un commentaire