[Resolved] Show WooCommerce price field using query loop?

Home Forums Support [Resolved] Show WooCommerce price field using query loop?

Home Forums Support Show WooCommerce price field using query loop?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2360887
    Phil

    Hi,

    Is there a way to show a woocommerce price field using the generate blocks query loop?
    I’ve got a query loop that shows the image and product name but I can’t see how to show any of the woocommerce fields.

    Thanks,
    Phil

    #2360949
    Fernando
    Customer Support

    Hi Phil,

    You can use a Dynamic GB Headline Block.

    Just set the Source to Post Meta, and the field name to _regular_pricefor instance.

    Reference: https://docs.generateblocks.com/article/headline-overview/#dynamic-data

    #2360981
    Phil

    Great, thanks Fernando.
    Is there a good way to format the field as currency, including the thousands separator?

    #2360995
    Fernando
    Customer Support

    Try adding my-query-price to the Class list of the Headline Block in its Advanced setting section. Then add this PHP snippet:

    add_filter('generateblocks_dynamic_content_output', function($content, $attributes, $block){
    	if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-query-price' ) !== false ) {
    		
    	$content = '$'. number_format($content);
    	}
    	return $content;
    }, 10, 3);

    Replace $ with your currency symbol.

    Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

    #2361034
    Phil

    thanks Fernando, perfect. 🙂

    #2361052
    Fernando
    Customer Support

    Your welcome Phil! 🙂

    #2554803
    Willya

    Hi David, it seems like the PHP code above to display the format is not working. I ‘ve tried it locally. And is it also possible to display a sale badge above the right of the product image?

    #2555211
    David
    Staff
    Customer Support

    Hi there,

    can you share a link to where we can see the issue ?

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