Tagged: woocomerce
-
AuthorPosts
-
July 21, 2016 at 3:12 pm #663423
Hello,
we found this code in an old post an insert it in the theme functions.php
add_action('ava_after_main_container', 'add_banner_before_breadcrumb'); function add_banner_before_breadcrumb() { if ( is_product() ) { echo '<h1 style="text-align: center;"><a href="http://www.yourwebsite.com" target="_blank"> <img border="0" alt="Banner Name" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image.jpg" style="float: left; z-index: 99999; width: 100%;"></h1>'; } }
this works fine for all product details page. but we want different headers on all category + the category header image for the specific detail pages.
Sample:
Header-1:
only Product Main PageHeader-2:
Category-1 main page
+ all product_detail pages from category-1 use header-2Header-3:
Category-2 main page
+ all product_detail pages from category-2 use header-3Header-4:
Category-3 main page
+ all product_detail pages from category-3 use header-4and so on….
many thanks for help! :-)
July 21, 2016 at 5:09 pm #663471the point is
if ( is_product() )
see reference here: https://docs.woocommerce.com/wc-apidocs/function-is_product.html
so you have to combine this rule f.e.:
function add_banner_before_breadcrumb() { if ( is_product() || is_product_category() ) {
etc.
if you want different on products and on categories than i think you have to use for each.
i’m not so familiar with that – so wait till a mod looks to your question if an if elseif case could work.add_action('ava_after_main_container', 'add_banner_before_breadcrumb'); function add_banner_before_breadcrumb() { if ( is_product() ) { echo '<h1 style="text-align: center;"><a href="http://www.yourwebsite.com" target="_blank"> <img border="0" alt="Banner Name" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image.jpg" style="float: left; z-index: 99999; width: 100%;"></h1>'; }; elseif ( is_product_category() ) { echo '<h1 style="text-align: center;"><a href="http://www.yourwebsite.com" target="_blank"> <img border="0" alt="Banner Name 2" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image2.jpg" style="float: left; z-index: 99999; width: 100%;"></h1>'; } }
- This reply was modified 8 years, 5 months ago by Guenni007.
July 21, 2016 at 5:23 pm #663481btw. you can see these logical operators here:
July 22, 2016 at 12:37 pm #663833Hi @envato1901,
Did you try @Guenni007’s suggestions and did you have any luck with them?
Thanks,
RikardJuly 22, 2016 at 2:53 pm #663895Hello,
yes, i try it – thanks to guenni007 :-)
the code now looks like:add_action('ava_after_main_container', 'add_banner_before_breadcrumb'); function add_banner_before_breadcrumb() { if ( is_product_category() AND has_term('6', 'product_cat')) { echo '<img border="0" alt="" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image-1.jpg" style="float: left; z-index: 99999; width: 100%;">'; } elseif ( is_product_category() AND has_term('17', 'product_cat')) { echo '<img border="0" alt="" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image-2.jpg" style="float: left; z-index: 99999; width: 100%;">'; } elseif ( is_product() ) { echo '<img border="0" alt="" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image-3.jpg" style="float: left; z-index: 99999; width: 100%;">'; } }
with the term id i can set the categories for the banner. but i dont know how i combinate category 6 + all only all products from cat. 6 have to use banner 1. And all products from category 17 have to use banner 2 from category 17. the last elseif ( is_product() ) must in elseif ( is_product_category() AND has_term(’17’, ‘product_cat’)).
July 26, 2016 at 7:23 am #665138if you like to select the category 17 and all products from category 17.
I don’t like to install a demo shop to help you – so you have to have a look for yourself.
if a single product is shown – doesn’t it have the product category too in his source code.
so when you selectis_product_category('17')
this does automatically even select all single products of that category?July 26, 2016 at 11:16 am #665239Hi,
thanks guys for sharing your wisdom with us :).
Best regards,
AndyJuly 26, 2016 at 1:19 pm #665287Hello,
no guenni007 it not works with is_product_category(’17’) for the single produtcs in the category. But now i think i have a solution for this. i will see if this works for more than three categories
add_action('ava_after_main_container', 'add_banner_before_breadcrumb'); function add_banner_before_breadcrumb() { if ( is_product_category || is_product AND has_term('17', 'product_cat')) { echo '<img border="0" alt="" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image-1.jpg" style="float: left; z-index: 99999; width: 100%;">'; } elseif ( is_product_category || is_product AND has_term('6', 'product_cat')) { echo '<img border="0" alt="" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image-2.jpg" style="float: left; z-index: 99999; width: 100%;">'; } elseif ( is_product_category || is_product AND has_term('16', 'product_cat')) { echo '<img border="0" alt="" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image-3.jpg" style="float: left; z-index: 99999; width: 100%;">'; } }
hope the code is conform with the rest of the code. :-)
July 27, 2016 at 12:02 pm #665668have some questions to the style experts.
how can I max . height for the banner determine. If I draw the window smaller the graphic is also small, it looks responsive. But the picture will be very squashed you can do this better? thanks for help!
August 24, 2016 at 2:03 pm #676967Hello,
where can I find the Term ID for the Main Page Shop where all categories are displayed? It use a wrong Banner from my code so i want to tell that it is empty.
elseif ( is_product AND has_term('HERE I NEED THE ID', 'product_cat')) { echo '<img border="0" alt="" src="http://xyz.com/wp-32e86-content/uploads/2016/08/mainpage_empty_banner.png" style="float: left; z-index: 99999; width: 100%;">'; }
August 24, 2016 at 2:24 pm #676975Hey!
That must be the main page to be honest ( shop from Pages ) and not the term ID. So I think it is better for that page, to replace it with is_page.
Let us know if that worksBest regards,
BasilisAugust 24, 2016 at 2:46 pm #676987Hello,
thanks for help!
when i only use
elseif ( is_page ) { echo 'Test Test Test'; }
the rest of the category code works but the Main Page do nothing. Have i to use for is_page the post ID from the Shopsite?
the products site have the post.php?=post=202 id.
August 29, 2016 at 1:41 pm #678873Hi,
yes, and or more information about this standard WordPress functions refer to: https://developer.wordpress.org/reference/functions/is_page/
Best regards,
Andy -
AuthorPosts
- You must be logged in to reply to this topic.