Skip Navigation

[Resolved] woocommerce related products slider using Essential Grid

This support ticket is created 7 years, 5 months 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 7 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#523320

I am trying to:
Add Essentil Grid code to the template file, or within a toolset field. The code is the following:
$ess_product_id = get_the_ID();
$ess_product_terms = get_the_terms( $ess_product_id, 'product_cat' );
foreach ($ess_product_terms as $ess_product_term) {
$ess_product_cat_id[] = $ess_product_term->term_id;
}
$ess_products_args = array(
'post_type' => 'product',
'post__not_in' => array($ess_product_id),
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $ess_product_cat_id,
'operator' => 'IN'
),
),
);

$ess_loop = new WP_Query( $ess_products_args );
while ( $ess_loop->have_posts() ) : $ess_loop->the_post();
$ess_list[] = get_the_id();
endwhile;
if(!empty($ess_list)){
echo do_shortcode('[ess_grid alias="related-prods" posts="' . implode(',', $ess_list) . '"]');

I visited this URL:
hidden link
This is the toolset enabled template file for this page. The accordian tabs are also linking to some other URLs not specified anywhere.
I expected to see:

Instead, I got:

#523415

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Zarrar

Can you confirm what you are aiming to do here?

On a custom product page you want to use essential grids to generate links to related products rather than use the standard WooCommerce related products content which you can generate with the wpv-woo-related_products shortcode, is that correct?

If you are using Toolset to create a custom single product template then the output for that will be generated by the content template (or layout) assigned to single products, you should not be editing PHP templates in this case.

You cannot add your PHP code above (I haven't checked the code to know if it should work or not, I assume you have) to the content template, but you can add custom shortcodes.

So try creating a custom shortcode (https://developer.wordpress.org/plugins/shortcodes/shortcodes/) for this. You don't echo your output from within a shortcode, you return it. If the [ess_grid] shortcode outputs a string then you should be able to simply return that.

#523442

Hi,
Thank you for the reply. That code is usually just placed in the template file. My question is what template file should be used in a child theme environment.

Thank you

#523443

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

If you are customising the single product page using Toolset then the template comes from the WooCommerce Views plugin (located at plugins/woocommerce-views/templates/single-product.php) and not the theme.

As such you can't edit it (or if you do any edits you make will be lost when you next update the plugin).

That is why you would need to add the essential grid using a shortcode in the Content Template (or Layout) assigned to single products.

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.