Adding global block to all woocommerce pages

I’m trying to place a global block below the nav on all woocommerce pages and I pulled some code from a previous thread, altered it, and placed it in the functions.php file. Nothing seems to have happened. I double checked my global block shortcode but past that point I can’t figure out what is wrong with it. A the very least I would like it on shop, category pages, and single product pages. Can you help?

function shop_header() { 
 if ( is_woocommerce() ) : ?>
		<div class="x-header-shop">
		    <?php echo do_shortcode('[cs_gb id=536]'); ?>
		</div>
<?php endif; 
}
add_action('x_after_masthead_end','shop_header', 30);

Hi @ryskamrr,

Thank you for writing in, but the credentials you provided did not work, please check.

That code is working, I have tested it on my local dev. Please make sure that is the correct shortcode of your Global Block, and make sure your child theme is active (Appearance > Themes).

Hope it helps,
Cheers!

sorry about that, I updated the pw in a secure note. Child theme is active and shortcode has been double checked.

I’ve been trying to get it to work. I’ve tried:

is_woocommerce()
is_shop()
is_product_category()
is_product_tag()

None of them produce anything for me.

Hello @ryskamrr,

The given credentials is not working for us.

By the way, you code is correct. Only the action hook is incorrect. Have you code updated and use this instead:

 function shop_header() { 
 	if ( is_woocommerce() ) : ?>
		<div class="x-header-shop">
		    <?php echo do_shortcode('[cs_gb id=536]'); ?>
		</div>
	<?php endif; 
}
add_action('x_before_view_global__slider-below','shop_header', 30);

The x_after_masthead_end will only work with the Pro theme. If you are using the X theme, you will have to use the hook given in the code above.

We would love to know if this has worked for you. Thank you.

Yes this worked great, thank you very much!

If anyone is interested in placing a different global block on something like the main shop page vs a category page I accomplished that by:

/**
 * Add global block above shop and category pages
 */
 function shop_header() { 
 	if ( is_shop() ) : ?>
		<div class="x-header-shop">
		    <?php echo do_shortcode('[cs_gb id=536]'); ?>
		</div>
	<?php endif; 
    if ( is_product_category() || is_product() || is_cart() || is_checkout() || is_account_page() || is_wc_endpoint_url() ) : ?>
		<div class="x-header-shop">
		    <?php echo do_shortcode('[cs_gb id=558]'); ?>
		</div>
	<?php endif; 
}
add_action('x_before_view_global__slider-below','shop_header', 30);

Hey @ryskamrr,

You are most welcome!
It’s good to know that it has worked for you.

Best Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.