简体   繁体   中英

Woocommerce shop page custom template

As I understand by default Woocommerce shop page uses product archive template. What I am looking for, is to use a custom template for shop page.

Here is what I did:

  1. Create template "my-shop"
  2. Create page "My shop" -> choose template "my-shop"
  3. Choose "My shop" as Woocommerce shop page

But none of the changes I made to "my-shop" template are present on the shop page.

What am I missing here? I would not like to change product archive itself, just the shop page.

Is there a way to disable product archive from being a default for shop page?

Thanks

I know it's too late and you may have figured it out by now. In any case, the changes that you would like to make to the WooCommerce Shop Page need to be done in the archive-product.php and it would be safer to create a child theme and do these changes. Making enhancements and customizations in a Child theme is best practice so that you can update the parent theme at any time and it won't affect your store.

I hope this helps, for more information on how you can use WooCommerce short-codes to customize your store can be found here .

To add to Silver Ringvee's answer - he used is_page but that only works on wordpress pages. For woocommerce you need to use something like is_woocommerce() . See Woocommerce conditional tags page.

My example code uses the is_shop conditional tag as that was the page you wanted to change. the code get_template_part( 'content', 'shop' ); will call the file content-shop.php in your theme root folder. This code is to be added at the top of wp-content\\themes\\*theme*\\woocommerce\\archive-product.php that you can copy from wp-content\\plugins\\woocommerce\\templates\\archive-product.php

You can add it just before get_header( 'shop' ); line 23 in my file - and the entire page will be drawn from your template. If you want to keep the header of the shop page, then put this code after the get_header code. Remember to include a footer in your file as well

if (is_shop()) {
 get_template_part( 'content', 'shop' );
} else  {  
#normal archive-product code here
}

The solution (not perfect) that I figured to work best, until someone finds a way to actually change the template from dashboard:

Adding:

<?php
if (is_page( 'Page Title' ) ):
  # Do your stuff
endif;
?>

to content-product.php in my theme's woocommerce folder.

If you prefer to go with code, you can create a redirect from the original shop page to your page via wp_redirect.

add_action('template_redirect', 'bc_010101_redirect_woo_pages');
function bc_010101_redirect_woo_pages()
{


 if (is_shop())
 {

  wp_redirect('your_shop_url_here');
  exit;
 }
}

More detailed tutorial can be found here

这不可能为商店页面创建自定义模板,仅将woocommerce模板复制并粘贴到主题文件夹中,然后尝试在content-product.php模板中工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM