简体   繁体   English

WooCommerce产品模板

[英]WooCommerce Product Template

I would like to move my thumbnails on my product template in WooCommerce, to position them beside the big product picture, underneath the price and add to cart buttons. 我想在WooCommerce的产品模板上移动缩略图,将其放在大产品图片旁边,价格下方并添加到购物车按钮。 (As standard, they are positioned directly underneath the big product picture) (作为标准,它们位于大产品图片的正下方)

The template seems to be using hooks though, and I haven't tried using that before. 该模板似乎正在使用钩子,而我之前从未尝试过使用它。 I have found a 'content-single-product.php' that seems to do the stuff, but I can't find anything about thumbnails in that file. 我已经找到一个似乎可以完成此工作的“ content-single-product.php”,但在该文件中找不到有关缩略图的任何信息。

Can someone point me in the right direction? 有人可以指出我正确的方向吗?

Thanks already! 已经谢谢你了!

First off, make sure you override WooCommerce templates in your theme directory in this folder structure: /woocommerce/templates/ (ie yourtheme/woocommerce/templates/). 首先,请确保在以下文件夹结构的主题目录中覆盖WooCommerce模板:/ woocommerce / templates /(即yourtheme / woocommerce / templates /)。 This way, if Woo has an update, your custom code won't be overridden. 这样,如果Woo有更新,您的自定义代码将不会被覆盖。

I'm not 100% positive on this, but generally having worked with Woo template overrides, this should get you pretty far. 我对此不是100%积极的看法,但是通常使用Woo模板替代,这应该会使您受益匪浅。

The thumbnails are actually in pretty deep. 缩略图实际上很深。

They are here: templates/single-product/product-thumbnails.php 它们在这里: templates/single-product/product-thumbnails.php

It's loaded in Line 43 here: woocommerce / templates / single-product / product-image.php 它在此处的第43行中加载: woocommerce / templates / single-product / product-image.php

That product-image.php section is loaded in here: woocommerce / templates / content-single-product.php "woocommerce_before_single_product_summary". 该product-image.php部分在此处加载: woocommerce / templates / content-single-product.php /content-single-product.php“ woocommerce_before_single_product_summary”。

So you will need to remove it from line 43 on the product-image.php and then put it in the "woocommerce_single_product_summary" section. 因此,您需要将其从product-image.php的第43行中删除,然后将其放在“ woocommerce_single_product_summary”部分中。 You should try and put this action add in your own custom functions file (obviously removing it - the action - from where it is now) which is 您应该尝试将此操作添加到您自己的自定义函数文件中(显然是将其从当前位置删除)。

add_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );

and change to 并更改为

add_action('woocommerce_after_single_product_summary','woocommerce_show_product_thumbnails', 20 );

The actions list is referenced here: 这里引用了动作列表:

woocommerce / includes / wc-template-hooks.php

The order is on 订单已开

woocommerce / templates / content-single-product.php

As Woocommerce suggests you are to put any overrides in a new folder under /your-theme-folder/woocommerce/. 正如Woocommerce所建议的那样,您要将所有替代项放在/ your-theme-folder / woocommerce /下的新文件夹中。 This is how it looks in sublime text 3 for me with 'framework' being the name of my theme. 就是我在崇高文字3中的外观,其中“框架”是主题的名称。

Now, under /your-theme-folder/woocommerce/single-product/product-image.php I commented out the original thumbnail hook like so. 现在,在/your-theme-folder/woocommerce/single-product/product-image.php下,我像这样注释掉了原始缩略图钩。

<?php //do_action( 'woocommerce_product_thumbnails' ); ?>

Next, I added a do_action to the template under /your-theme-folder/woocommerce/ in the content-single-product.php file in woocommerce_single_product_summary hook. 接下来,我在woocommerce_single_product_summary钩子的content-single-product.php文件中的/ your-theme-folder / woocommerce /下的模板中添加了一个do_action。

<div class="summary entry-summary">

    <?php
        /**
         * woocommerce_single_product_summary hook
         *
         * @hooked woocommerce_template_single_title - 5
         * @hooked woocommerce_template_single_rating - 10
         * @hooked woocommerce_template_single_price - 10
         * @hooked woocommerce_template_single_excerpt - 20
         * @hooked woocommerce_template_single_add_to_cart - 30
         * @hooked woocommerce_template_single_meta - 40
         * @hooked woocommerce_template_single_sharing - 50
         */
        do_action( 'woocommerce_single_product_summary' );
        do_action( 'woocommerce_product_thumbnails' );

    ?>

</div><!-- .summary -->

You should now see your thumbnails inside the div with class summary and entry-summary. 现在,您应该在div内看到包含类别摘要和条目摘要的缩略图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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