php - Adjust price if addons are set -


hi have woocommerce addons plugin in wordpress shop, users choose weight , calculate price upon weight, have code adds main price price of kg, example cake costs 100$ per kg

in cart shows 700$ 6 kg's. must show 600. adds main price after calculation.

here code

public function add_cart_item( $cart_item ) {     // adjust price if addons set     if ( ! empty( $cart_item['addons'] ) && apply_filters( 'woocommerce_product_addons_adjust_price', true, $cart_item ) ) {            foreach ( $cart_item['addons'] $addon ) {             if ( $addon['price']  ) {              }         }          $cart_item['data']->adjust_price($addon['price'] );     }      return $cart_item; } 

$cart_item['data']->adjust_price($addon['price'] ); doesn't expecting have. in wooocmmerce/includes/abstructs/abstruct-wc-product.php on line 776 see price passed being added previous price. in place have override old price, not adjusting. or may can subtract original price prior adjustment.

option 1: overriding price

$cart_item['data']->set_price($addon['price'] ); 

option 2: adjusting price

$price = (float) $cart_item['data']->get_price($addon['price'] ); $adjustable_price = (float) $addon['price']  $cart_item['data']->adjust_price( $adjustable_price ); 

hope might you.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -