Override Wholesale Only Shipping Setting For Certain Shipping Methods

Override Wholesale Only Shipping Setting For Certain Shipping Methods

In WooCommerce 2.6.0 shipping zones were introduced which prompted us to release a new version of WooCommerce Wholesale Prices Premium with enhanced shipping mapping controls.
One of those enhancements is to do with a setting called Wholesale Only Shipping Methods which hides all mapped shipping methods from non-wholesale customers.
This is an important feature to allow admins to hide shipping methods that are exclusively for wholesale customer use. A common example of this might be Local Pickup which might only be offered to wholesale customers.
As of 1.9.5, for advanced users, we have also added a new filter which lets you selectively choose to override this setting and expose certain shipping methods to non-wholesale customers.
The idea here is that you enable the setting because that is the default behaviour, but there might be certain shipping methods that you actually do want to expose to customers.
You can use this filter to achieve that by putting the following code into your functions.php file in your theme.
To make all non-zoned shipping methods available:
// Allow all non-zoned shipping methods to be available to regular users
function allowMappedNonZonedMethodsForRegularUsers( $allow, $shipping_method ) {

if ( ! $shipping_method->supports( 'shipping-zones' ) )
$allow = true;

return $allow;

}

add_filter( 'wwpp_force_allow_mapped_shipping_method_for_non_wholesale' , 'allowMappedNonZonedMethodsForRegularUsers', 10, 2 );

Or for a specific non-zoned shipping method:
// Allow non-zoned shipping method "Advanced Free Shipping" only to be available to regular users
function allowAdvancedFreeShippingForNonWholesale( $allow, $shipping_method ) {

if ( ! $shipping_method->supports( 'shipping-zones' ) && $shipping_method->id == 'advanced_free_shipping' )
$allow = true;

return $allow;

}

add_filter( 'wwpp_force_allow_mapped_shipping_method_for_non_wholesale' , 'allowAdvancedFreeShippingForNonWholesale', 10, 2 );

Need to allow a different shipping method other than Advanced Free Shipping?
Just use the ID key of your shipping method, eg. UPS shipping method is 『ups』, USPS is 『usps』 and so on.
Contact your developer to find out what the ID of the shipping method is you need.

How To Give A Further Discount Off Wholesale Price When Product Is In A Certain Category

How To Give A Further Discount Off Wholesale Price When Product Is In A Certain Category

In some cases you might like to setup a special 「Wholesale On Sale」 product category which houses items that give a further discount based on the Wholesale Price, not the Regular Price.
Instead of having to manually adjust prices or percentage points, it』s possible to do this in code to give a further discount on the wholesale price for items that appear in this 「Wholesale On Sale」 category.
Note that I』m specifically talking about giving the discount off the wholesale price, not the regular price. For adjusting the % off the regular price use the product category percentage discounts feature for that.
This is intended as an advanced tutorial and should only be implemented if you have a good understanding about User roles and Product Categories terms.
Add the following code snippet to your functions.php and adjust the category slug (I』ve used 「wholesale-on-sale」 here) and the percentage off you wish to give (0.5 is used here for 50% off). You can also add more 「else if」 conditions to test for other role or other categories too.
/**
* Add further discount on top of a product's wholesale price.
* The function below give a further discount on the wholesale price for items in the "Wholesale On Sale" category.
* Important Note: Please adjust this functions code accordingly to fit your needs.
*/
function wwppAddDiscountToSaleCategory( $wholesalePrice , $product_id , $userWholesaleRole ) {

// Get all the category slugs this product belongs to
$terms = wp_get_post_terms( $product_id, 'product_cat' );
$categories = array();

foreach ( $terms as $term )
$categories[] = $term->slug;

/**
* Check if this product is under the "wholesale-on-sale" product category.
* Assuming that we wanted to apply 50% off on all products under this category on top of their existing wholesale price
* Please change 'wholesale-on-sale' category accordingly to fit your needs.
*/
if ( in_array( 'wholesale-on-sale', $categories ) ) {

/**
* Check if the current user have a role of 'wholesale_customer'.
* Assuming we wanted to have this effect on all users under 'wholesale_customer' role.
* Please change the role accordingly to fit your needs.
*/
if ( in_array( 'wholesale_customer', $userWholesaleRole ) ) {

/**
* In this example we are using 50% discount off from the product existing "wholesale price".
* Please change accordingly to fit your needs.
*/
if ( is_array( $wholesalePrice ) && isset( $wholesalePrice[ 'wholesale_price' ] ) )
$wholesalePrice[ 'wholesale_price' ] = $wholesalePrice[ 'wholesale_price' ] - ( $wholesalePrice[ 'wholesale_price' ] * 0.5 );
else
$wholesalePrice = $wholesalePrice - ( $wholesalePrice * 0.5 );

}

// You can add more else if conditions here if you want to test for other wholesale roles

}

// you can add more else if conditions here to test for other product categories

return $wholesalePrice;
}

add_filter( 'wwp_filter_wholesale_price_shop_v2', 'wwppAddDiscountToSaleCategory', 100, 3 );

add_filter( 'wwp_filter_wholesale_price_cart', 'wwppAddDiscountToSaleCategory', 100, 3 );

// You only need to uncomment this if you are using WooCommerce Wholesale Prices plugin lower than verison 1.6.x
// If you are on the latest version of our plugins, no need to uncomment this code to improve performance
// add_filter( 'wwp_filter_wholesale_price', 'wwppAddDiscountToSaleCategory', 100, 3 );

Quantity Based Tiered Pricing for Product Categories Guide

Quantity Based Tiered Pricing for Product Categories Guide

Product categories can apply a quantity based tiered % discount beyond the defined base wholesale % discount to all eligible products in the cart that belong to that product category.
The quantity based tiered % discount pricing structure applies to these eligible products based on the sum total of all products in that category that are in the cart, even if some products belong to other categories as well (and are applying % rates from other categories) or are using product based prices.
Please refer here for a detailed explanation of the hierarchy of how pricing is applied in WooCommerce Wholesale Prices.
The best way to illustrate how quantity based tiered pricing on categories affects products on the cart is with a few examples:
Example #1: Tiers apply to the sum of all products from that category in the cart

Category 1 has a base wholesale % discount of 20%.
It also has a quantity based tiered % discount for quantity 10 – 100 which gives the customers 50% off instead.
Product A and Product B both belong to Category 1.
Product A』s regular retail price is $100. Product B』s regular retail price is $150.
Neither product has a wholesale price set on the product and therefore will be using category % based pricing.

If the cart contains:

Product A – 6
Product B – 3

No quantity based tiered % discounts will apply to either product. Only the base wholesale % discount for the category applies.

Product A – $80 each
Product B – $120 each

However, if the cart is updated to contain:

Product A – 6
Product B – 5

The sum of all products from Category 1 in the cart is greater than the 10 minimum of the tiered discount and therefore the quantity based tiered % discount (50% off) will apply.

Product A – changes to $50 each
Product B – changes to $75 each

Example #2: Tiers apply to the sum of all products, even if some products aren』t using those tiers themselves

Category 1 has a base wholesale % discount of 20%.
It also has a quantity based tiered % discount for quantity 10 – 100 which gives the customers 50% off instead.
Product A and Product B both belong to Category 1.
Product A』s regular retail price is $100. Product B』s regular retail price is $150.
Product A does not define a wholesale price on the product and therefore will be using category % based pricing.
Product B does define a wholesale price of $125.

If the cart contains:

Product A – 6
Product B – 3

No quantity based tiered % discounts will apply to either product. Only the base wholesale % discount for the category applies.

Product A – $80 each
Product B – $125 each

However, if the cart is updated to contain:

Product A – 6
Product B – 5

The sum of all products from Category 1 in the cart is > than the 10 minimum of the tiered discount, and therefore the quantity based tiered % discount (50% off) will apply.

Product A – changes to $50 each
Product B – stays at $125 each

Product B』s price does not change because, as per the pricing hierarchy, once a wholesale price is defined on the product category % discounts do not apply.
However, it』s presence in the cart means it does still count towards the sum of all products from each of it』s categories. It』s presence in the cart may affect the pricing of other products in the cart in the same category that are using category % discounts.
Example #3: Products that belong to multiple categories count towards the sum total of products in all their categories

Category 1 has a base wholesale % discount of 20%.
Category 2 has a base wholesale % discount of 10%
Category 1 also has a quantity based tiered % discount for quantity 10 – 100 which gives the customers 50% off instead.
Product A belongs to Category 1 only.
Product B belongs to Category 1 and Category 2.
Product A』s regular retail price is $100. Product B』s regular retail price is $150.
Neither product has a wholesale price set on the product and therefore will be using category % based pricing.
The global setting for 「Category Wholesale Discount」, which determines which category to use when a product belongs to multiple categories, is set to use the 「Lowest」 % discount.

If the cart contains:

Product A – 6
Product B – 3

No quantity based tiered % discounts will apply to either product. Only the base wholesale % discount for the category applies.
Product A will use Category 1』s base wholesale % discount of 20%, while Product B will use Category 2』s base wholesale % discount of 10% (the lower of the two that Product B belongs to).

Product A – $80 each
Product B – $135 each

However, if the cart is updated to contain:

Product A – 6
Product B – 5

The sum of all products from Category 1 in the cart is greater than the 10 minimum of the tiered discount,and therefore the quantity based tiered % discount (50% off) will apply.

Product A – changes to $50 each
Product B – stays at $135 each

Product B』s price does not change because it is using the base wholesale % discount from Category 2.
However, it does still count towards the sum of all products from each of it』s categories and it』s presence may affect the pricing of products in the same category that are using category % discounts.

How to Hide Unused Wholesale Price Settings on the Product Backend

How to Hide Unused Wholesale Price Settings on the Product Backend

Our WooCommerce Wholesale Prices Premium automatically adds a number of extra fields to your product edit screens which can take up quite a bit of room on the interface. For example, the Wholesale Minimum Order Quantity, Wholesale Order Quantity Step and Product Quantity Based Wholesale Pricing fields.

These fields are here so you can properly configure the sales conditions for your product, however, some users might not be using one or more of these pricing features in their wholesale shop at all.
If you want to declutter/hide those unused wholesale prices settings on the product backend, simply modify the snippet below to adjust which wholesale pricing feature that you want to hide from your product settings. Then put it to your theme or child theme』s functions.php file. This will hide those features on the backend interface.
add_action('admin_head', 'hide_wws_product_settings');

function hide_wws_product_settings() {
echo '
/*Wholesale Minimum Order Quantity*/
.wholesale-minium-order-quantity-options-group{
display:none!important;
}
/*Wholesale Order Quantity Step*/
.wholesale-order-quantity-step-options-group{
display:none!important;
}
/*Product Quantity Based Wholesale Pricing*/
.product-quantity-based-wholesale-pricing{
display:none!important;
}
';
}

How To Give Zero Wholesale Price Or Free Product Wholesale Customers Only

How To Give Zero Wholesale Price Or Free Product Wholesale Customers Only

It』s possible to give zero wholesale priced products or free wholesale products to your wholesale customers by simply setting the wholesale price as zero on the individual product setting.
However, if you want to enable the Only Show Wholesale Products to Wholesale Users, which defines wholesale products as products that have wholesale price defined that is greater than zero, it will hide the zero-wholesale priced products to your wholesale customers.

Fortunately, there are a few tricks that you can do to bypass this setting.
The first workaround is by creating a Product Category Wholesale Discount to your Wholesale User and setting the discount to 100%. Products that are in this category will get zero wholesale price and will still become visible to wholesale customers even the Only Show Wholesale Products to Wholesale Users setting is enabled.
The second workaround is related to decimal numbers. If your number of decimals on the WooCommerce setting is set as 2 (default), you can give zero wholesale price by entering the wholesale price value as 0.001. This will still display as zero priced wholesale product to your wholesale customers and works even with Only Show Wholesale Products to Wholesale Users setting is enabled.

How to hide crossed-out regular price to wholesale customers

How to hide crossed-out regular price to wholesale customers

By default, when a wholesale customer logs in to view the wholesale products on the cart, the regular price is crossed out and the wholesale price is displayed:

You can remove the crossed our retail price to your wholesale customers by going to WooCommerce > Settings > Wholesale Prices > Price and enable the Hide Original Price. Now, only the wholesale price is displayed to your wholesale customers.

How To Keep Retail Prices Showing Including Tax When Wholesale Price Is Set To Show Excluding Tax

How To Keep Retail Prices Showing Including Tax When Wholesale Price Is Set To Show Excluding Tax

When a wholesale customer visits the product page, the default view is that they see the regular price crossed out with the wholesale price.
Our WooCommerce Wholesale Prices Premium has a feature to allow your wholesale customers to view a separate tax display to your shop, cart, and checkout pages.
For example, you can set Including Tax to regular price and set Excluding Tax to your wholesale prices. However, if you set excluding tax to your wholesale customers, they will also see the crossed out regular price with excluding tax.
So if you want to keep the regular price with including tax, you just need to use this custom snippet and put it to your theme/child theme』s functions.php.
global $wc_wholesale_prices_premium;
remove_filter( 'option_woocommerce_tax_display_shop' , array( $wc_wholesale_prices_premium->wwpp_tax, 'wholesale_tax_display_shop' ) );
remove_filter( 'option_woocommerce_tax_display_cart' , array( $wc_wholesale_prices_premium->wwpp_tax, 'wholesale_tax_display_cart' ) );

Now, when wholesale customers check your wholesale products, the crossed out regular price will display including tax while your wholesale price shows ex tax.

How To Prevent Purchase If Wholesale Conditions Are Not Met

How To Prevent Purchase If Wholesale Conditions Are Not Met

Our WooCommerce Wholesale Prices Premium has a feature to set a minimum order requirement. If the wholesale customer doesn』t meet this requirement, there』ll be a notice for them to warn them about this because they won』t get the wholesale price for that order. 
If by chance your wholesale customer misses this, they will still be able to checkout with regular price. 
We also have an option to prevent purchases/check out if the wholesale customer hasn』t met the minimum order requirement. Since this is enabled per user role (not globally) you』ll find this on the wholesale roles page with the user』s role-specific settings.
To enable this, please navigate to WooCommerce > Wholesale Roles, then edit the Wholesale Customer and tick the 「Prevent purchase if wholesale condition is not met」 option. 

Create Wholesale Only Content With These Special Shortcodes

Create Wholesale Only Content With These Special Shortcodes

In the latest version of WooCommerce Wholesale Prices Premium we introduced several new shortcodes which allow you to show or hide content in any post, page or product or basically anywhere you can use shortcodes.
This is super powerful as you can imagine and leads to being able to show different product page content to wholesale customers, showing hidden information like links to wholesale only resources and more.
How To Use The Wholesale Only Content Shortcodes
To hide content from regular users but show it to wholesale customer use:
[wholesale_content]Here is my content that is only visible to any wholesale user[/wholesale_content]
Or if you want to do the opposite, that is hide content from wholesale users but show to everyone else simply:
[hide_from_wholesale]Content that any wholesale user should not see[/hide_from_wholesale]
You can also target specific wholesale roles with these shortcodes:
[wholesale_content role="wholesale_second_level,wholesale_third_level"]Here is my content that is only visible to the specified roles[/wholesale_content]
And target specific wholesale roles when hiding content too:
[hide_from_wholesale role="wholesale_second_level"]Content that is hidden from the second level wholesale role[/hide_from_wholesale]
We hope you have fun using these new shortcodes!

How to automatically run the Re-Initialize Visibility Meta button after every import using WP All Import

How to automatically run the Re-Initialize Visibility Meta button after every import using WP All Import

After importing your products using a third party plugin like WP All Import, your products are not re-saved in a traditional way like what is discussed in this article. If this happens, you just need to click the Re-initialize Product Visibility Meta on the Help tab of our Wholesale Price settings, to save the correct wholesale meta values in the database.
However, some customers update their products more often, usually via a scheduled import using a CRON job. It will be difficult for them to keep manually clicking this button each time they import their products. So the best workaround for this is to use the snippet below to automatically run the re-initialize button each time an import is made.
Please put this snippet on your theme/child theme』s functions.php:
function wwpp_product_visibility_fix() {
$wwpp = WooCommerceWholeSalePricesPremium::instance();
$wwpp_wholesale_roles = WWPP_Wholesale_Roles::instance();
$wwpp_wholesale_role_payment_gateway = WWPP_Wholesale_Role_Payment_Gateway::instance( array( 'WWPP_Wholesale_Roles' => $wwpp_wholesale_roles ) );
$wwpp_bootstrap = WWPP_Bootstrap::instance( array(
'WWPP_Wholesale_Roles' => $wwpp_wholesale_roles,
'WWPP_Wholesale_Role_Payment_Gateway' => $wwpp_wholesale_role_payment_gateway,
'WWPP_CURRENT_VERSION' => $wwpp::VERSION
) );
$wwpp_bootstrap->initialize_product_visibility_filter_meta();
}
add_action( 'pmxi_after_xml_import', 'wwpp_product_visibility_fix' );

Please note that this custom snippet is a filter for a function called 『pmxi_after_xml_import』. It is a function from WP All Import, which means that the code should run after the importing of your products.
If you』re using other third-party plugins, we suggest contacting the plugin author or ask a developer to provide further assistance regarding this snippet.