Okay
  Public Ticket #3761395
Price Shortcode / Code Snippet
Closed

Comments

  •  6
    Miguel Zenha started the conversation

    Hi!

    I want to show the price in the product page with custom styling.

    To do that, I want to get the wholesale price and the retail price in PHP. Is this possible? I mean, is there any code snippet to print out these type of information?

    Best regards and tanks

  •  2,281
    WebWizards replied

    Hello Miguel,

    First, I just want to mention that the plugin does have a feature that can show B2B users both prices:

    https://woocommerce-b2b-plugin.com/docs/how-to-display-rrp-recommended-retail-price-to-b2b-users/

    With this feature, B2B users will see both prices. These prices have special classes that you could use for CSS styling.

     

    Specifically regarding your question on how to get those prices in PHP:

    -> Could you clarify, is your goal to show these 2 prices to all users (e.g. including logged out users), or only to logged in B2B users?

    I ask as the code would be different.

     

    Kind regards,

    Stefan

  •  6
    Miguel Zenha replied

    Hi!

    Sorry about the late response.

    That is exactly what I was looking for. I activated that option and the B2B users can now see the recommended retail price (RRP) and the wholesale price.

    However, I want to show the price in different areas of the product page, and that is why I opened this ticket, because styling it with CSS is not the best option.

    I have a custom code snippet that shows the RRP price by getting the product price: 

    $product->get_regular_price();


    But how can I get the price for the user that is currently logged in? There are 2 groups of B2B users.

    https://prnt.sc/c8ETc6eVxJw2

    About your question:
    -> Could you clarify, is your goal to show these 2 prices to all users (e.g. including logged out users), or only to logged in B2B users?

    The store that we are developing has restricted access. We activated the "Hide website / force login" option, so only logged in users can see the prices.

    Best regards and thanks for the assistance!


  •  6
    Miguel Zenha replied

    Hi Stefan!

    Any news on this ticket? Can you please help me with this?

    Best regards and thanks

  •  2,281
    WebWizards replied

    Hello Miguel,

    Apologies for the delay on this, we are seeing an unusually high volume of tickets at the moment,

     

    To get the price for the current logged in user, I believe this code should work:

    // get price for the logged in user (wholesale price)
    if ($product->is_on_sale()){
    	$price = $product->get_sale_price();
    } else {
    	$price = $product->get_regular_price();
    }

    B2BKing filters the results of those get_regular_price / get_sale_price functions, so those should show the price as it is for the current logged in users (For a B2B user, this would show the B2B price).

     

    To get the retail price, I would suggest to use:

    $regular_price = get_post_meta($product->get_id(), '_regular_price', true);

     

    If it would help, we can transform these code snippets into shortcodes, perhaps so you can better place them in your desired location.

     

    If you find the above do not get an accurate price in your tests, possibly some adjustments are needed to the snippets, e.g. to adjust for tax (but I am not sure as it can depend on site tax settings).

    If you can share a backend login to the site or a staging site, I'd be happy to check directly and work to make sure the prices are accurate.

     

     

  •  6
    Miguel Zenha replied

    Hi Stefan,

    I'm sorry to hear that you are having a lot of work.
    The code snippet that you have sent me is working totally fine.

    I have not yet made the TAX adjustments in the website, but I will check if it is working after making those changes.

    Thanks a lot for the assistance. You're great.

    Best regards and thanks