FB Pixel

WooCommerce Wholesale Prices and Product Bundles conflict

A few weeks back one of our customers began using the WooCommerce Product Bundles plugin and reported an issue to us where the cart total was double what it should be. After some investigation we found there to be a conflict with the WooCommerce Wholesale Prices plugin. In this article we’ll outline the details of the conflict and how we were able to fix it.

We were able to narrow down the conflict to the WooCommerce Wholesale Prices plugin by deactivating all other plugins (except WooCommerce itself, of course) temporarily; when this cleared up the issue, we knew it was a plugin conflict and proceeded to re-activate each plugin one-by-one until the issue came back. (The customer hadn’t noticed that the issue was only present for Wholesalers, or this narrowing-down might have been a bit quicker.)

Looking through the action/filter hooks in this plugin we found the below, which changes the price values of items in the cart to the wholesale price if the current visitor is logged in as a wholesaler:

add_action( 'woocommerce_before_calculate_totals', 'wwp_simple_add_cart_price' );  function wwp_simple_add_cart_price( $cart_object ) {  	$current_user = new WP_User(wp_get_current_user()->ID);  	$user_roles = $current_user->roles;  	$current_role = get_option('wwo_wholesale_role');  	foreach ($user_roles as $roles) {  	if  ($roles == $current_role ){   		foreach ( $cart_object->cart_contents as $key => $value ) {  			$wholesale = get_post_meta( $value['data']->id, '_wholesale_price', true );  			$wholesalev = get_post_meta( $value['data']->variation_id, '_wholesale_price', true );  				if ($wholesale){$value['data']->price = $wholesale;}  				if ($wholesalev){$value['data']->price = $wholesalev;}  		}  	}

When not using the “Per-item Pricing” option, the Product Bundles plugin filters each bundle item to have a price of $0 in the cart. The code above from the Wholesale Prices plugin ends up changing this from $0 to the defined price for wholesalers.

The approach we took was to replace the function above with a modified version that will not change the price for wholesalers if the price is already $0. We’ll do this by removing the action defined in the plugin and adding our own. Formatting differences aside, the only modification to the function is to wrap the price changes in an if-statement that checks to see if the price is greater than $0.

remove_action( 'woocommerce_before_calculate_totals', 'wwp_simple_add_cart_price' );  add_action( 'woocommerce_before_calculate_totals', 'gowp_wwp_simple_add_cart_price' );  function gowp_wwp_simple_add_cart_price( $cart_object ) {  	$current_user = new WP_User(wp_get_current_user()->ID);  	$user_roles = $current_user->roles;  	$current_role = get_option('wwo_wholesale_role');  	foreach ($user_roles as $roles) {  		if  ($roles == $current_role ){  	 		foreach ( $cart_object->cart_contents as $key => $value ) {  	 			if ( $value['data']->price > 0 ) {  					$wholesale = get_post_meta( $value['data']->id, '_wholesale_price', true );  					$wholesalev = get_post_meta( $value['data']->variation_id, '_wholesale_price', true );  					if ($wholesale){$value['data']->price = $wholesale;}  					if ($wholesalev){$value['data']->price = $wholesalev;}  				}  			}  		}  	}  }

As with all things WordPress, there is more than one way to address this. Also, this is not intended as a turn-key solution – copy/pasting this into your own project may not work if your particular setup is different, but it should get you pointed in the right direction.

The Landing Page Builds service includes:

  • Unlimited page builds for one monthly rate
  • Dedicated account manager
  • Dedicated WordPress developer
  • At least 2 hours of daily dev time
  • Daily progress reports
  • Find out more here

The Content Edits Plan includes:

  • Unlimited content edits
  • White label help desk
  • Support ticket dashboard
  • 24/7 team of WordPress experts
Plus, everything in our Maintenance Plan:
  • Visual Validator WordPress updates
  • 90 days of off-site backups
  • Daily security scans and malware cleanup
  • Maintenance dashboard
  • Find out more here

The Maintenance Plan includes:

  • Visual Validator WordPress updates
  • 90 days of off-site backups
  • Daily security scans and malware cleanup
  • Maintenance dashboard
  • Find out more here