• Resolved Anders Madsen

    (@itmesteren)


    Hello

    I have a shortcode [products categories=”cat-a”] in my header.
    If I enter the shop page for cat-a the product shortcode won’t show any products because it hooks into the product shortcode.

    I’d like it not to do that.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author annastaa

    (@annastaa)

    Hello Itmesteren,

    It’s true that filters hook into all the Woocommerce queries that are run on shop page, including those belonging to shortcodes. Problem is, sometimes this behavior is desirable: some builders and themes re-write the main Woocommerce loop, but whenever they use native Woocommerce hooks, the filters still work. Quite a few of existing plugin users rely on this functionality, so unfortunately we are rather reluctant to revise this piece of code.

    Could you perhaps consider using the native Woocommerce “Products by Category” widget instead of the shortcode to display the contents of your header category? Filters should not interfere with the work of this widget, and it has an absolutely different HTML markup to not get affected by AJAX calls.

    If the usage of “Products by Category” widget solution is not agreeable for whatever reason and you have a child theme and are willing to resolve the issue by custom adjustments, here is what you can do:

    1. Go to the annasta Filters > Product lists admin section, and set the Products html wrapper setting to a unique identifier for the wrapping container of the main (filterable) products list of your shop page (click on the link above for explanations on how to find the wrapper).

    2. Add the following code at the end of the functions.php file of your child theme:

    function annasta_remove_shop_page_shortcodes_support( $attrs ) {
    	if( is_shop() && class_exists( 'A_W_F' ) && !empty( A_W_F::$front ) ) {
    		remove_filter( 'woocommerce_product_query_tax_query', array( A_W_F::$front, 'set_wc_tax_query' ) );
    		remove_filter( 'woocommerce_product_query_meta_query', array( A_W_F::$front, 'set_wc_meta_query' ) );
    		remove_filter( 'loop_shop_post_in', array( A_W_F::$front, 'get_wc_post__in' ) );
    	}
    
    	return $attrs;
    }
    add_filter( 'shortcode_atts_products', 'annasta_remove_shop_page_shortcodes_support' );
    Thread Starter Anders Madsen

    (@itmesteren)

    Understandable you can’t change it, before you responded I took the crazy person option and made my own shortcode to display products haha!

    An excellent response though! have 5 stars

    Plugin Author annastaa

    (@annastaa)

    Hello again Itmesteren,

    You obviously knew what you were doing ?? It’s always a great moment to realize that there can be more than 1 (2/3?) solutions to the given problem, when addressed from different angles! I will go ahead and mark this thread as resolved then, hopefully our discussion helps the future users who run into the same issue.

    Thank you for supporting our work with a good review, have a great day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Plugin filters woocommerce product shortcode’ is closed to new replies.