Skip Navigation

[Closed] Specific View for products that are children of a specific term (Woocommerce)

This support ticket is created 9 years, 10 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 9 years, 10 months ago.

Assigned support staff: Luo Yang.

Author
Posts
#74744

Hi there,

I have a shop and the owner has said they want to have two types of website. one selling normal products and the other selling training courses. Now, the former is easy as it is the default setting for Woocommerce and works quite nicely with the theme I'm using.

I am stuck on whether there is a way to force a product to be displayed using a certain view if it is a child of a particular taxonomy. Do you know if this is possible or, indeed, if there is another workaround for this?

All the best,

Steve

#75763

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hi Steve,

I suggest you modify your theme file, such as single-product.php, use wp function has_term to check if current post is a child of a particular taxonomy, then output the view.

More help: Check if the current post has any of given terms.
http://codex.wordpress.org/Function_Reference/has_term

render_view Renders a view and returns the HTML output.
https://toolset.com/documentation/views-php-integration/

Regards
Luo

#75872

Hay there,

Sorry, I used the wrong terminology there. It's my fault. What I meant was is there a way to force a product to be displayed using a certain view template?

All the best,

Steve

#76286

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

It is not possible with Views, but you can try create a shortcode for it, like this:
1) add codes in your theme/functions.php

function has_term_func($atts, $content) {

	extract(shortcode_atts(array(
		'term' => 'my-term',
		'taxonomy' => 'my-taxonomy',
		'condition' => 1,
	), $atts));
	$res = '';
	if( (has_term( $term, $taxonomy ) && $condition) || (!has_term( $term, $taxonomy ) && !$condition)) {
	   $res = do_shortcode($content);
	}
	return $res;
}
add_shortcode( 'has-term', 'has_term_func' );

2) merge your views template into one, put the shortcode [has-term] into it, like this

[has-term]
product that is a child of a specific term
[/has-term]

[has-term condition=0]
product that is not a child of a specific term
[/has-term]

Please let me know if you need assistance to do it

The topic ‘[Closed] Specific View for products that are children of a specific term (Woocommerce)’ is closed to new replies.