Home › Forums › WoodMart support forum › Assigning a header to a product depending on the category it is in
Assigning a header to a product depending on the category it is in
- This topic has 18 replies, 2 voices, and was last updated 5 years ago by
Artem Temos.
-
AuthorPosts
-
October 28, 2019 at 2:03 pm #152938
Danny96ParticipantHi,
In the product page theme settings, you can assign a header that is different for just a single product page. However, I have 2 main categories on my website that I want to have 2 different colour headers to differentiate between the 2, is there anyway to change the product page headers to match each category.
For example, if i have a sports category that has a green header, can I assign the sports products to have the green header? Whilst at the same time, having the non-sports products have a blue header, to match the non-sports category header of being blue?
Kind regards
October 28, 2019 at 2:26 pm #152950
Artem TemosKeymasterHello,
Sorry, but there is no such ability in our theme at the moment. We will consider implementing this in the future.
Kind Regards
February 2, 2020 at 8:32 pm #171107
Danny96ParticipantHi,
Could you tell me in which file the headers are changed? Also, is the header id used to change the header or is it the name of the header? I’m not sure how it changes, does it use the get_header()?
Thanks
February 2, 2020 at 8:40 pm #171108
Danny96ParticipantAlso, where are the headers saved. I see a lot online people referring to get_header(‘shop’) which then people change ‘shop’ to the header-“variable”.php file. Will my created headers in header builder have these types of files?
Thanks
February 3, 2020 at 7:09 am #171148
Artem TemosKeymasterHello,
The header builder doesn’t work as a default WordPress header. You can find how it works in the files located in the folder
woodmart/inc/builder/
.Kind Regards
February 3, 2020 at 9:01 am #171180
Danny96ParticipantHi,
In which file does it check for a page-id to assign that specific header to that page.
Could I not add to this using a product category id? I.e. if product-cat id = 1 then use header 1, if product-cat id = 2 use header 2. Could it work in that way?
Thanks
February 3, 2020 at 9:02 am #171182
Artem TemosKeymasterIt is located in the file
inc/builder/Frontent.php
in the method calledget_current_id
.February 3, 2020 at 9:58 am #171198
Danny96ParticipantHi,
Would I need to target:
$custom_product_header = woodmart_get_opt( ‘single_product_header’);
Assign a specific header based on the product category id? Would I need to recreate this?:
$page_id = woodmart_page_ID(); but change to product_category_id?
If I am understanding this wrong, could you explain this bit of code so I can understand it more?
Attachments:
You must be logged in to view attached files.February 3, 2020 at 12:18 pm #171236
Artem TemosKeymasterTry to add the following PHP code snippet to the child theme functions.php file to do this. Replace ids
10
and11
with your categories ids andheader_576762
with header ids.add_filter( 'woodmart_get_current_header_id', function ( $id ) { if ( is_product_category() && is_object( get_queried_object() ) ) { if ( get_queried_object()->term_id == 10 ) { return 'header_576762'; } elseif ( get_queried_object()->term_id == 11 ) { return 'header_496420'; } } return $id; } );
February 3, 2020 at 12:39 pm #171243
Danny96ParticipantHi,
I tried this but it didn’t work.
Do I need to change term_id to tag_id?
I’ll attach a screenshot – I used 582 as the term-id and header_449732 as the header id. Are these the correct ids?
Thanks
Attachments:
You must be logged in to view attached files.February 3, 2020 at 12:53 pm #171248
Danny96ParticipantHi, would this also work for product pages? For example, if i had a hoodie product, the header on that hoodie product would be the ‘hoodie header’, i dont just want it on the archive page.
In total, i only want 2 different headers – green header for products in the ‘leisurewear category’ and a blue header for products in the ‘sportswear category.
Sorry if i didn’t make this clear.
Thanks
February 4, 2020 at 6:59 am #171351
Artem TemosKeymasterThis code will work on the category pages only. As for the product, you can assign them manually for each product while editing them.
February 4, 2020 at 9:13 am #171381
Danny96ParticipantHi,
How do I assign a specific header to a product?
Thanks
February 4, 2020 at 9:45 am #171391
Artem TemosKeymasterSorry, my mistake and I see that this option is missed at the moment. We will add this feature in our next theme update.
February 4, 2020 at 9:49 am #171392
Danny96ParticipantHi,
do you know when this update will go live?
Thanks
February 4, 2020 at 4:05 pm #171473
Danny96ParticipantHi,
if the code is similar to the category assigning you provided above, could I be supplied with that? So then I can assign product ids in the same way as category ids?
Thanks
February 4, 2020 at 5:53 pm #171393
Artem TemosKeymasterIt will be available in a few weeks.
February 4, 2020 at 9:48 pm #171525
Danny96ParticipantHi,
great news!
Is the code similar to the product category way you showed above? Just as a temporary solution so I can see it working. Would I need to change is_product_category() and change term id to product id?
February 5, 2020 at 6:56 am #171555
Artem TemosKeymasterThis code and the feature we will introduce do different things. The code is for product categories pages and the option will work on the single product page only.
-
AuthorPosts
Tagged: Product Change Header, Product Headers
- You must be logged in to create new topics. Login / Register