Skip to content
Advertisement

Why Woocommerce update price programmically not working in woocommerce_add_cart_item_data hook

i have 2 type of products : 1- products that have regulare price 2- products that have calculated price

i added some hidden field to product page form with below code :

JavaScript

and send these fields data to cart item by :

JavaScript

and at last using woocommerce_before_calculate_totals hook to change product price by this code :

JavaScript

now problem is that $final_price variable not working when $_POST[‘agop-new-price’] and $_POST[‘agop-shipping-method-price-number’] are exists together What part of my code is wrong?

Advertisement

Answer

i found the problem: i used woocommerce_product_get_price and woocommerce_product_get_regular_price filters, Which affected the checkout and cart pages. So I put the commands of these filters in a condition like the following code and the problem was solved 🙂

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement