Site logo

[Support request] Show product price in query block

Home Forums Support [Support request] Show product price in query block

Home Forums Support Show product price in query block

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2561251
    Kees

    Hi,

    We are building a website for a hotel. On the home page they want three blocks with information about three different rooms. We can not get the priceof each room in her. Can you tellus how to show the price of each room? Maybe with a shortcode?

    Thank you!

    #2561274
    David
    Staff
    Customer Support

    Hi there,

    when you say product. Is this using Woocommerce or is it a regular post type with the price saved in the post meta ?

    #2561316
    Kees

    Hi,

    Yes, it is a WooCommerce product with a queryblock. We use generateblocks pro. So we show 3 products and we need to get the price.

    How do we fix this?

    Regards,
    Niek

    #2561360
    David
    Staff
    Customer Support

    Option 1 – the unformatted price:

    Use a Headline with > Dynamic Data

    Data Source: Current Post
    Content Source: Post Meta
    Post Meta Field: _price

    Option 2 – the formatted price

    1. Add this PHP Snippet to your site:

    add_filter( 'render_block', function( $block_content, $block ) {
        if ( 
            ! empty( $block['attrs']['className'] ) 
            && 'ql-price' === $block['attrs']['className']  
        ) { 
            $price = get_post_meta( get_the_ID(), '_price', true );
            $formatted_price = wc_price( $price );     	
            $block_content = str_replace( 'ql-price', $formatted_price , $block_content );
        }
    
        return $block_content;
    
    }, 10, 2 );

    2. Add a Headline block to your loop, and give it a static text of: ql-price
    And in Advanced > Additional CSS Class(es) add: ql-price

    NOTE: in both options we set the _price as the post meta field.
    Woo has other values including _regular_price and _sale_price

    I have tested both methods on a simple product

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.