Skip Navigation

[Resolved] conditional widget on woo category archive pages

This thread is resolved. Here is a description of the problem and solution.

Problem:

The customer created WooCommerce archive pages using Toolset and wanted to display a widget in those archive pages only. They used the is_product_category() conditional wrapper, but the widget content did not appear on the front end. The customer was unsure if a different conditional wrapper was needed because the WooCommerce archive was created using Toolset.

Solution:

We suggested using the woocommerce_page_title hook to add the conditional, which worked in a similar setup. Additionally, we provided an alternative solution involving the creation of a custom shortcode [is_tax_sc] to check if the current page is an archive page of a specific taxonomy (in this case, 'product_cat'). This shortcode could then be used with Toolset’s conditional shortcode to display the widget only on the product archive pages. The customer later confirmed that the issue was resolved after switching from a Genesis page hook to a WooCommerce hook.

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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 3 replies, has 2 voices.

Last updated by Mateus Getulio 4 months, 1 week ago.

Assisted by: Mateus Getulio.

Author
Posts
#2713521

Hi ive created our woocommerce archive pages with toolset and have a widget area id like to display on those archive pages only However when I wrap the widget with
is_product_category()

The widget content doesn't appear on the front end of the site.

Do i need a different conditional wrapper to work with the toolset created wordpress archives

Thanks

#2714857

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

I apologize for the delay caused to the weekend.

Can you please share screenshots on how you're setting it up so that I have a better idea of what could be causing it not to work?

Thank you,

Please let me know.
Mateus

#2715803

Thanks Mateus and no worry about the weekend I wasnt expecting a response until today

Here's my function- As i mentioned the widget works and the content is display every where if i remove the
if ( is_product_archive() ) {
} conditional. So my questions was is there a different way of creating the conditional due to the fact that the woo archive is created in toolset

function woo_menu_widget() {

if ( is_product_archive() ) {
genesis_widget_area( 'woo-menu', array(
'before' => '<div class="woo-menu">',
'after' => '</div>',
) );
}
}

Thanks

#2716197

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello Steve,

Thank you for the further information. Are you using a hook to add the conditional?

I created a similar setup and was able to show a widget only in products archive using the 'woocommerce_page_title' hook:

add_filter( 'woocommerce_page_title', 'customize_woocommerce_product_archive', 101, 1 );
function customize_woocommerce_product_archive( $page_title) {	
  if ( is_product_category() ) {
    // Widget code goes here  
  }
}

Alternatively, you can also use a conditional shortcode by following the steps:

1) Create a custom shortcode to check current page is archive page of taxonomy "product_cat", for example add below codes into your theme file functions.php:

add_shortcode("is_tax_sc", function($atts){
	$atts = shortcode_atts( array(
		'tax' => '',
	), $atts);
	$res = 0;
	if(is_tax($atts['tax'])){
		$res = 1;
	}
	return $res;
});

This will create a custom shortcode [is_tax_sc] to check if current page is archive page of specific taxonomy, in our case 'product_cat'

2) Dashboard-> Toolset-> Settings-> Front-end Content
in section "Third-party shortcode arguments", add the shortcode name: is_tax_sc

3) Use above shortcode like this:

[wpv-conditional if=" ( '[is_tax_sc tax="product_cat"]' eq '1' ) "  evaluate="true"]
// widget goes here
[/wpv-conditional]

I tested the second method and I was able to customize the conditional shortcode to only product archive.

Can you please give it a try?

Thank you,
Mateus

#2718155

Mateeus thanks the issue was my hook I was using a genesis page hook and i needed a woo hook Im all good now