Home > Mobile >  My woocommerce before shop loop hook is not working?
My woocommerce before shop loop hook is not working?

Time:02-26

So i have edited my function.php file to contain the following code. However on my shop page it is not showing up at all. I tried increasing the number from 12 to 40, but no difference. I also show my product-archive.php file below. I tried using a do_action(etc etc), but it breaks since the do_action runs in the product-archive.php

    add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' );

function add_google_script(){
        echo "HELLO HELLO HELLO";
}
add_action('woocommerce_before_shop_loop', 'add_google_script', 12);```

//If my product-archive.php

```if ( woocommerce_product_loop() ) {

    /**
     * Hook: woocommerce_before_shop_loop.
     *
     * @hooked woocommerce_output_all_notices - 10
     * @hooked woocommerce_result_count - 20
     * @hooked woocommerce_catalog_ordering - 30
     */

    do_action( 'woocommerce_before_shop_loop' );``` 

CodePudding user response:

I'm not completely sure what you want to achieve. But this snippet should add the content before the product loop:

add_action( 'woocommerce_before_shop_loop', 'add_google_script', 12 );
function add_google_script(){
    if (is_product_category()) :
        echo "HELLO HELLO HELLO";
    endif;
}

CodePudding user response:

Use this action, it will work.

add_action( 'woocommerce_before_shop_loop', 'action_woocommerce_before_shop_loop', 10, 2 ); 
  • Related