Skip Navigation

[Resolved] Looping & separators for parent fields

This support ticket is created 7 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Noman 7 years ago.

Assisted by: Noman.

Author
Posts
#593818

Nik

Hi

I am creating a layout for items which call on three fields in a parent table - 'Price in $', 'Price in €', 'Price in £'.

Only one currency price may exist, or two or three.

What is the best way to get these into my layout with a comma separator? That is, if there is only one price I don't want a comma after it.

Is the best way to do this in the layout itself, or with a content template, or with a view?

Thanks

#593947

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Register Shortcode.png

Hi Nik,

Thank you for contacting Toolset support. We can achieve it using multiple if conditions for commas.
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

Sometime conditional statements not working in layout, So that we can use content template for it.
1. If you want to compare woocommerce price field in if condition then you need to add following code in functions.php file:

// Add Custom Shortcode
function get_product_price ( $atts ) {
 
    // Attributes
    $atts = shortcode_atts(
        array(
            'product_id' => '',
        ),
        $atts
    );
 
    if( function_exists('get_product') ){
        $product = new WC_Product( $atts['product_id']);
        $price = $product->price;
         
        return $price;
    }
 
}
add_shortcode( 'get_product_price', 'get_product_price' );

2. Register shortcode first in Toolset >> Settings >> Front-end Content >> Third-party shortcode arguments sections -- screenshot attached for example.

3. And then use following shortcode in your content template or view:


[wpv-conditional if="( '[get_product_price product_id='[wpv-post-id]']' ne '' )"]
Price is [wpv-woo-product-price]
[/wpv-conditional]

If still issue arise, please provide temporary access WP-Admin Login info to your site. Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please provide backend-end screenshot and highlight the fields which are having this issue.

Thank you