I create some orders programmatically via the Woo API, the standard endpoints for creating an order, nothing special.
But when I create an order via API for a customer that belongs to a user group and should have a discount, this discount does not apply for this API-created order.
The same customer has discount when the order is submitted via checkout.
1. Do you have compatibility with Woo API, or not? I always though that you have compatibility with Woo API because is something basic and commonly used. I'm a little surpised it doesn't work!
2. If no compatibility exists, is it something you could do in a reasonable ETA?
3. If no compatibility exists and you can't provide it, can you guide me or point me to a direction of how to implement it myself? Is it possible?
This is quite complex I'm afraid, and I'm not aware of a simple way to solve it.
The biggest issue is that a lot of the hooks that WooCommerce uses to modify prices are only frontend-hooks and they do not have a backend equivalent - basically they mostly only work with the frontend cart. B2BKing generally uses 5-15 hooks for each pricing feature and dynamic rule, in total probably 150+ hooks and pricing functions.
To give you an example, we use functions like $cart_item['data']->set_price( $individual_meta_price ); to set price, but in an API order there's no cart and no cart items.
This makes it very difficult to reproduce the same pricing functionality we have on the frontend,
We ran into this issue for manual backend orders. There we worked on an integration for backend orders to apply basic prices like group prices (but not more complex rules), but even that was very difficult because the same code does not apply and you basically have to write everything from scratch.
Most role-based pricing plugins run into this issue and last I checked B2BKing was the only one that had this capability for manual backend orders.
We have not worked on this for API orders, but I believe it's the same challenge.
Maybe it could work to activate the same code path we use for backend orders, though I have not had a chance to try it. Can you please try to add this code to your functions.php, and replace 1234 with the customer ID of the customer you're trying to create an order for via REST API:
I create some orders programmatically via the Woo API, the standard endpoints for creating an order, nothing special.
But when I create an order via API for a customer that belongs to a user group and should have a discount, this discount does not apply for this API-created order.
The same customer has discount when the order is submitted via checkout.
1. Do you have compatibility with Woo API, or not? I always though that you have compatibility with Woo API because is something basic and commonly used. I'm a little surpised it doesn't work!
2. If no compatibility exists, is it something you could do in a reasonable ETA?
3. If no compatibility exists and you can't provide it, can you guide me or point me to a direction of how to implement it myself? Is it possible?
Thank you
Hi Dimitris,
This is quite complex I'm afraid, and I'm not aware of a simple way to solve it.
The biggest issue is that a lot of the hooks that WooCommerce uses to modify prices are only frontend-hooks and they do not have a backend equivalent - basically they mostly only work with the frontend cart. B2BKing generally uses 5-15 hooks for each pricing feature and dynamic rule, in total probably 150+ hooks and pricing functions.
To give you an example, we use functions like $cart_item['data']->set_price( $individual_meta_price ); to set price, but in an API order there's no cart and no cart items.
This makes it very difficult to reproduce the same pricing functionality we have on the frontend,
We ran into this issue for manual backend orders. There we worked on an integration for backend orders to apply basic prices like group prices (but not more complex rules), but even that was very difficult because the same code does not apply and you basically have to write everything from scratch.
Most role-based pricing plugins run into this issue and last I checked B2BKing was the only one that had this capability for manual backend orders.
We have not worked on this for API orders, but I believe it's the same challenge.
Maybe it could work to activate the same code path we use for backend orders, though I have not had a chance to try it. Can you please try to add this code to your functions.php, and replace 1234 with the customer ID of the customer you're trying to create an order for via REST API:
Then try to send the order via API. Does that help with prices at all?
If not, I think the only solution is to directly specify the price of each item in your rest api request,
Kind regards,
Stefan