Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'woocommerce_before_calculate_totals', 'woo_custom_addons_plugin_custom_cart_items_prices', 10, 1 );
- function woo_custom_addons_plugin_custom_cart_items_prices( $cart_object ) {
- global $prices,$add_ons;
- if ( is_admin() && ! defined( 'DOING_AJAX' ) )
- return;
- foreach ( $cart_object->get_cart() as $cart_item ) {
- // get the product id (or the variation id)
- $id = $cart_item['data']->get_id();
- // GET THE NEW PRICE (code to be replace by yours)
- $explode = explode(" - ",$cart_item['data']->get_name());
- if(isset($explode[1])){
- $add_on_id = $add_ons->getByName($explode[1]);
- if($add_on_id !== 0 && $prices->getPricePerQuantity($add_on_id,$cart_item['quantity']) !== false){
- $new_price = $prices->getPricePerQuantity($add_on_id,$cart_item['quantity']); // <== Add your code HERE
- // Updated cart item price
- $cart_item['data']->set_price( $new_price );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment