should return the correct price for the current user (either the b2b or b2c price depending on whether the user is b2b or b2c).
It would be helpful if you can explain in more detail what you are trying to achieve. I would like to give it some thought and maybe I can provide you with a simpler or more elegant solution, or at least save you some time,
Hi, Stefan!
We are now changing the store to a hybrid B2B & B2C shop and we are facing some issues.
I want to build a shortcode to check if the user is a B2C or B2B.
If the user role is null or it's not logged in, then we assume that it is a B2C guest.
After that, we want to show the B2C or B2C price ($product->get_regular_price() / $product->get_sale_price()).
How can we do this code snippet in PHP?
Best regards and thanks.
Hello Miguel,
Glad to assist,
Generally you can use this PHP function to check if a user is B2B or B2C:
However, if your goal is to simply separate B2B and B2C prices, well, B2BKing does that automatically.
These functions:
should return the correct price for the current user (either the b2b or b2c price depending on whether the user is b2b or b2c).
It would be helpful if you can explain in more detail what you are trying to achieve. I would like to give it some thought and maybe I can provide you with a simpler or more elegant solution, or at least save you some time,
Kind regards,
Stefan
Hi Stefan!
I managed to get it working.
The goal was to show the price without taxes to b2c users, and the price with tax to b2c users.
I can leave the code here in case someone needs to do something similar:
In my case, the tax is 23%.
Example: a product that costs 200€ with tax, shows up like this:
B2C users: €200
B2B users: 162.60 + TAX
I used the following code:
Best regards and thanks