• Resolved kojaa

    (@kojaa)


    Hello,

    I would like to use different header and footer instead of default one, I already achieved this but I can’t manage to do it for WooCommerce templates. So let me explain what is happening.

    Website is using Storefront child theme, and the current structure looks like this:
    – for the desktop version:
    /mytheme/woocommerce/

    – for the amp version:
    /mytheme/amp/woocommerce/
    – In order for the amp woocommerce templates to load, I use this code:

    
     function woo_amp_directory ($path){
    	if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
    	   $my_path = get_stylesheet_directory() . '/amp/woocommerce/';
    	   return file_exists( $my_path ) ? 'amp/woocommerce/' : $path;
    	}
    	return $path;
     }
     add_filter ('woocommerce_template_path', 'woo_amp_directory');
    

    Now I have my custom header & footer in the /mytheme/amp/ directory and I load it using
    get_template_part('amp/header', 'amp');
    get_template_part('amp/header', 'amp');

    However the WooCommerce templates are using the get_header() & get_footer() function which loads the header from /mytheme/. I would like to override this behaviour so the templates that are in /mytheme/amp/woocommerce/ use this:
    get_template_part('amp/header', 'amp');
    get_template_part('amp/header', 'amp');
    instead of default ones.

    It doesn’t specifically need to use the get_template_part function, i just want these templates /mytheme/amp/woocommerce/ to use /mytheme/amp/header.php & /mytheme/amp/footer.php.

Viewing 12 replies - 1 through 12 (of 12 total)
  • James Osborne

    (@jamesosborne)

    @kojaa Are you able to locate the get_header() functions in your theme? If so can you copy and use the same is_amp_endpoint function you used previously in your current themes functions.php or a custom plugin? You should then be able to point the WooCommerce header & footer to your regular /mytheme/amp/ directory.

    Or share the full WooCommerce get_header()code and I can see if I can assist further.

    Thread Starter kojaa

    (@kojaa)

    Hello,

    I was able to locate get_header() function in some areas, such as single-product.php , in that part i just replace get_header() & get_footer() with my header & footer functions. For example in /woocommerce/my-account/ none of the templates inside have get_header() or get_footer() function and i can’t seem to find where is the code that loads header & footer for those templates. Because of that original get_header() & get_footer() are being loaded which loads default header.php & footer.php from theme directory. This would be fine behaviour if get_header() & get_footer() was loading header.php & footer.php from /mytheme/amp/ on AMP pages.

    James Osborne

    (@jamesosborne)

    @kojaa While I didn’t get an opportunity to check myself yet are you able to copy your preferred header and footer templates into your /mytheme/amp/woocommerce/auth directory?

    Thread Starter kojaa

    (@kojaa)

    I’ve tried putting header and footer in /mytheme/amp/woocommerce/auth but that didn’t work.

    Thread Starter kojaa

    (@kojaa)

    Hello,

    It’s been few days, i still didn’t manage to get this working, i would really like to get this working and would appreciate any help.

    James Osborne

    (@jamesosborne)

    @kojaa Apologies for the delay, I’ll look into this for you when time allows and report back here.

    It doesn’t seem like an issue with the AMP plugin specifically, as you’re looking to use your current themes header and footer into your custom WooCoommerce templates, but I will get back to you on this as soon as I can.

    Thread Starter kojaa

    (@kojaa)

    No problem, thanks.

    James Osborne

    (@jamesosborne)

    @kojaa I had a chance to look at this today, can you try the following:

    1. Create a duplicate your themes header.php, from the “Storefront” theme directory
    2. Rename it header-amp.php and keep it in the same location
    3. In your amp/woocommerce directory wherever you wish to use header-amp replace get_header( 'shop' ) with get_header( 'amp' )

    As you’ve already created your own header replace the contents in header-amp.php as you wish. You can repeat the above for your footer.

    Thread Starter kojaa

    (@kojaa)

    Hello,

    I’ve already tried this, the problem is, if I put get_header('amp') or get_template_part('amp/header', 'amp'); in /mytheme/amp/woocommerce/myaccount/my-account.php , it will load it without problems, but it will also load the original header.php from /mytheme/ directory which breaks the website. Also I don’t use child theme anymore i now use my own version of storefront theme since I had to do a lot of modifications (nothing really changed i just reduced number of folders and files i have to go through).

    Thread Starter kojaa

    (@kojaa)

    The problem is also that i can’t find where original header.php is being loaded, there is no get_header() in any of templates that are in /mytheme/amp/woocommerce/myaccount/

    Thread Starter kojaa

    (@kojaa)

    I managed to fix this problem. The issue was that woocommerce was loading page.php and not my custom template.

    @kojaa Thanks for the follow up. That’s good to know, we can keep that in mind for any future users who made encounter the same issue.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Loading different header and footer in woocommerce templates’ is closed to new replies.