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

Viewing 19 posts - 1 through 19 (of 19 total)
  • Author
    Posts
  • #152938

    Danny96
    Participant

    Hi,

    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

    #152950

    Artem Temos
    Keymaster

    Hello,

    Sorry, but there is no such ability in our theme at the moment. We will consider implementing this in the future.

    Kind Regards

    #171107

    Danny96
    Participant

    Hi,

    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

    #171108

    Danny96
    Participant

    Also, 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

    #171148

    Artem Temos
    Keymaster

    Hello,

    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

    #171180

    Danny96
    Participant

    Hi,

    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

    #171182

    Artem Temos
    Keymaster

    It is located in the file inc/builder/Frontent.php in the method called get_current_id.

    #171198

    Danny96
    Participant

    Hi,

    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.
    #171236

    Artem Temos
    Keymaster

    Try to add the following PHP code snippet to the child theme functions.php file to do this. Replace ids 10 and 11 with your categories ids and header_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;
    	}
    );
    #171243

    Danny96
    Participant

    Hi,

    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.
    #171248

    Danny96
    Participant

    Hi, 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

    #171351

    Artem Temos
    Keymaster

    This code will work on the category pages only. As for the product, you can assign them manually for each product while editing them.

    #171381

    Danny96
    Participant

    Hi,

    How do I assign a specific header to a product?

    Thanks

    #171391

    Artem Temos
    Keymaster

    Sorry, my mistake and I see that this option is missed at the moment. We will add this feature in our next theme update.

    #171392

    Danny96
    Participant

    Hi,

    do you know when this update will go live?

    Thanks

    #171473

    Danny96
    Participant

    Hi,

    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

    #171393

    Artem Temos
    Keymaster

    It will be available in a few weeks.

    #171525

    Danny96
    Participant

    Hi,

    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?

    #171555

    Artem Temos
    Keymaster

    This 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.

Viewing 19 posts - 1 through 19 (of 19 total)