Hello @davidreca
The issue you are describing with Divi and BodyCommerce occurs because the WooCommerce Wholesale Prices (WWP) plugin, by default, only injects wholesale data into its own custom REST API namespace (wholesale/v1). When BodyCommerce uses the standard WooCommerce REST API (wc/v3) to refresh the shop page via filters, the wholesale prices are not included in the response.
To resolve this, let the BodyCommerce developers try this. They can follow these steps to ensure wholesale prices are correctly returned in their REST API requests:1. Enable Wholesale Data on Standard REST Endpoints
WWP uses a check to determine if the current request is a “wholesale endpoint.” BodyCommerce can use the wwp_is_wholesale_endpoint filter to tell WWP to treat their requests as wholesale requests.
add_filter( 'wwp_is_wholesale_endpoint', function( $is_wholesale, $request ) {
// Check if this is a BodyCommerce request (adjust the condition as needed)
// For example, you can check for a specific parameter or the route
if ( strpos( $request->get_route(), 'wc/v3/products' ) !== false ) {
return true;
}
return $is_wholesale;
}, 10, 2 );
2. Pass the wholesale_role Parameter
For WWP to know which wholesale prices to return, the REST API request should include a wholesale_role parameter. BodyCommerce should add this to their AJAX/REST calls:
- Parameter:
wholesale_role
- Value: The role of the current user (e.g.,
wholesale_customer).
If this parameter is present and the request is identified as a wholesale endpoint (using the filter above), WWP will add a wholesale_data object to each product in the JSON response.3. Accessing the Wholesale Data in the Response
Once the above is implemented, the product JSON response will contain a new field called wholesale_data. This object includes:
price_html: The formatted HTML price (including the “Wholesale Price:” label).
wholesale_price: The raw wholesale price for the requested role.
BodyCommerce should use the wholesale_data.price_html value if they are rendering the price on the frontend from the JSON response.Summary for BodyCommerce Developers
- Filter to Use:
wwp_is_wholesale_endpoint (return true for your requests).
- Request Parameter: Add
wholesale_role to your REST API queries.
- Response Field: Look for the
wholesale_data property in the product object returned by the API.
Alternatively, if you want a global fix for all REST requests on the site, you can add this snippet to the site’s functions.php:
add_filter( 'wwp_is_wholesale_endpoint', '__return_true' );
Just a reminder, this will add wholesale data to all product REST responses, which may increase response size slightly.