Custom Search Template for Custom Post Types

Try adding the return as well in the else{}, like this: function template_chooser($template) { global $wp_query; $post_type = get_query_var(‘post_type’); if( $wp_query->is_search && $post_type == ‘product’ ) { return locate_template(‘archive-products.php’); } else { $args = array_merge( $wp_query->query, array( ‘post_type’ => ‘post’ ) ); query_posts( $args ); return locate_template(‘archive-products.php’); } return $template; } add_filter(‘template_include’, ‘template_chooser’); Haven’t tested.

How do you search for a post by custom taxonomy?

For the record I found an answer to this question in the end – I needed to use a meta query rather than a taxonomy query. The correct code ended up being this: $relatedBlogPostArgs = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => 1, ‘order’ => ‘DESC’, ‘orderby’ => ‘date’, ‘meta_query’ => array( array( … Read more

Woocommerce: deleted single-product.php, everything still works. How is it possible?

Themes can override WooCommerce default template pages, to customize the appearance of those pages easily. There should be a folder within your theme folder called woocommerce. WooCommerce checks for template files within that folder first. If a file doesn’t exist there, it loads it’s own template file. Edit: If you want to customize those pages, … Read more

Quotes not rendering properly in WooCommerce settings API [closed]

You’re creating a string representation of an array, when you need an actual array! $blogusers = get_users(); $options = array(); foreach ( $blogusers as $user ) { $options[ $user->user_email ] = $user->user_email; // No need to pass through __(), don’t translate emails! } And then pass it to your options argument: $this->form_fields = array( ‘sec_r2_mail’ … Read more

Woocommerce Price Text

Just use the $product parameter to get the custom field value, and determine what to return: function custom_price_html( $price, $product ) { if ( ( int ) get_post_meta( $product->id, ‘price_per_person’, true ) ) $price .= ‘ per person’; elseif ( ( int ) get_post_meta( $product->id, ‘price_per_group’, true ) ) $price .= ‘ per group’; $price … Read more

Woocommerce Filter Main Loop by Tag [closed]

First Question: Solved by copying and modifying the “archive-product.php” template file. if(is_product_tag(array(‘audio’))) : include ‘archive-product-audio.php’; // includes custom loop else: // default archive loop endif; Second Question: Solved by simply filtering the Recent Products shortcode via “function.php”. add_filter(‘woocommerce_shortcode_products_query’, ‘removeAudioTags’); function removeAudioTags($args){ $args[‘tax_query’] = array(array( ‘taxonomy’ => ‘product_tag’, ‘field’ => ‘slug’, ‘terms’ => array(‘audio’), ‘operator’ => … Read more