Answer the question
In order to leave comments, you need to log in
Add 1 item to cart as Woocommerce different items?
Hello everyone, I have implemented an additional input for entering the length in the product card. The price of the goods is indicated per meter, a person enters, enters the length of the pole, the number of pieces, and the total number of meters and the amount are calculated for him. When I click on the add to cart button, I change the price of the product as follows:
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
function add_custom_price( $cart_object ) {
$length = (int)$_POST['length'];
$price = (int)$_POST['price'];
$itog = ($length / 1000)*$price;
$target_product_id = 15713;
foreach ( $cart_object->cart_contents as $key => $value ) {
if ( $value['product_id'] == $target_product_id ) {
$value['data']->set_price((int)$itog);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question