Discounts: Custom User Role Based Wholesale Discounts

Customized the discounts for wholesale user roles. To be used with the Autoship Cloud Wholesale Extension 

Important: Always test customizations to your site on a staging environment before making changes to your live / production site.  If you are not experienced with testing changes on a staging site, here is a good article to review.

/**
* Adjusts the default additional percent discount given wholesale
* users for Autoship wholesale products. Specific to the Autoship Cloud Wholesale Extension
*
* @param array $discounts                     The current array of role => discount pct.
* @param int $id                              The product id.
* @param string $user_wholesale_role          Current User's role.
* @param array $user_wholesale_roles          Current User's role(s).
*
* @return array The filtered discount percentages.
*/
function xx_extend_adjust_wholesale_autoship_discount_percentage( $discounts, $id, $user_wholesale_role, $user_wholesale_roles ){

    // Adjust the default for the Wholesale customer to 25%
    $discounts['wholesale_customer'] = .25;
  
    // Add a new role discount of 10% for Veteran Family
    $discounts['veteran_family'] = .1;
  
    return $discounts;
  
  }
  add_filter( 'autoship_wholesale_saleprice_autodiscount_by_wholesale_role', 'xx_extend_adjust_wholesale_autoship_discount_percentage', 10, 4 );

Still need help? Contact Us Contact Us