Hey there, I have a store where we import all our prices excluding tax and then adjust tax settings accordingly in b2bking and or the code of the website. Our tax is displaying for logged in users using a code snippet.
//add tax for b2c logged in add_filter( 'woocommerce_get_price_html', 'bbloomer_alter_price_display2', 9999, 2 );
function bbloomer_alter_price_display2( $price_html, $product ) {
// ONLY ON FRONTEND
// ONLY IF PRICE NOT NULL if ( '' === $product->get_price() ) return $price_html;
// IF CUSTOMER LOGGED IN, APPLY 15% TAX if ( wc_current_user_has_role( 'customer' ) ) { $orig_price = wc_get_price_to_display( $product ); $price_html = wc_price( $orig_price * 1.15 ); }
return $price_html;
}
as you can see with the if statement i check if the are logged in as customer and then apply the tax. I tried creating a new function like this to add the tax to the guest users with no luck as Im not sure what to set the role as or how to identify guest users in b2bking.
I also tried setting the VAT with the included dyanmic rules but that does not work at all.
Please could you look into providing me the identifier for guest users on b2bking so they can also see the correct including VAT price?
Hey there, I have a store where we import all our prices excluding tax and then adjust tax settings accordingly in b2bking and or the code of the website. Our tax is displaying for logged in users using a code snippet.
//add tax for b2c logged in
add_filter( 'woocommerce_get_price_html', 'bbloomer_alter_price_display2', 9999, 2 );
function bbloomer_alter_price_display2( $price_html, $product ) {
// ONLY ON FRONTEND
// ONLY IF PRICE NOT NULL
if ( '' === $product->get_price() ) return $price_html;
// IF CUSTOMER LOGGED IN, APPLY 15% TAX
if ( wc_current_user_has_role( 'customer' ) ) {
$orig_price = wc_get_price_to_display( $product );
$price_html = wc_price( $orig_price * 1.15 );
}
return $price_html;
}
as you can see with the if statement i check if the are logged in as customer and then apply the tax. I tried creating a new function like this to add the tax to the guest users with no luck as Im not sure what to set the role as or how to identify guest users in b2bking.
I also tried setting the VAT with the included dyanmic rules but that does not work at all.
Please could you look into providing me the identifier for guest users on b2bking so they can also see the correct including VAT price?
Hi Ethan,
I believe I have replied to this via a Comment, but let me copy paste the reply below:
-----------
I am not if the code snippet in your message copied correctly because I can’t see any if statement and the code seems incomplete.
Generally how this works with our plugin is that tax is configured in WooCommerce->Settings->Tax->Tax Rates. Then with B2BKing you would create a Tax Exemption dynamic rule to specify which users should NOT see tax. (I am not sure if you looked at this but we describe this process here: https://woocommerce-b2b-plugin.com/docs/how-to-display-prices-excluding-tax-for-b2b-users-and-including-tax-for-b2c-users/ )
To answer your question specifically, with PHP code you can use the following identifiers:
1) Logged Out Users (guest users):
if (!is_user_logged_in()){ // code here }
2) Logged Out Users (guest users) + logged in B2C:
if (get_user_meta(get_current_user_id(), ‘b2bking_b2buser’, true) !== ‘yes’){ // code here }
3) Logged In B2C:
if (is_user_logged_in() && (get_user_meta(get_current_user_id(), ‘b2bking_b2buser’, true) !== ‘yes’)){ // code here }
4) Logged in B2B:
if (get_user_meta(get_current_user_id(), ‘b2bking_b2buser’, true) === ‘yes’){ // code here }
--------------
You can reply here to follow up,
Kind Regards,
Stefan