How to edit what's displayed in the Woocommerc

2019-05-31 04:04发布

I'm doing some work for a client and using wordpress / woocommerce, they asked me to move the categories to be located directly under the product name on a single product page which I have done, but they don't want it to print "categories: category 1, category 2 etc..." they would like the "categories:" removed and it to just actually lists the names of the categories without the label.

Normally this would be easy enough but I cant find the PHP anywhere that generates the divs that are in. Its with <div class="post_in"> which is nested in <div class="product_meta">.

We are using "The Retailer" theme from theme forest if that makes a difference. You can see an example of what im talking about at http://www.sophieferreira.com/?product=down-the-rabbit-hole-onyx-print

2条回答
We Are One
2楼-- · 2019-05-31 04:25

My clean solution to the problem of overriding meta.php (replicable for any other script hookable)

Copy meta.php from woocommerce plugin

plugins/woocommerce/templates/single-product/meta.php

To your theme folder

themes/mytheme/content-single-product-meta.php

Then in functions.php just remove and add the action this way:

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );

Add again the same action but using a different second parameter (the name of the replacing function to be evaluated)

add_action( 'woocommerce_single_product_summary', 'custom_woocommerce_template_single_meta', 40);

And finally add the replacing function

function custom_woocommerce_template_single_meta(){
    wc_get_template( 'content-single-product-meta.php' );
}

From now on you can safely change your html/php inside content-single-product-meta.php and override the default, without actually editing the original woocommerce php, so that if you need to upgrade the plugin you won't risk to lose your modifications.

I hope this helps.

查看更多
小情绪 Triste *
3楼-- · 2019-05-31 04:38

Are you using the most current version of WooCommerce? If so, look in your plugins folder and navigate to "woocommerce -> templates -> single-product -> meta.php". Look on line 27 and you should see at least one location where this is being created. Try to edit that line and see if it works for you.

Keep in mind, anytime you are editing the WooCommerce template files you should move them into your theme folder. This way you will still be able to update WooCommerce without overwriting your edits. You can edit these files in an upgrade safe way through overrides. Simply copy it into a directory within your theme named /woocommerce, keeping the same file structure except you don't include the templates folder. So to override the meta.php file the structure inside of theme folder would be: woocommerce -> single-product -> meta.php

查看更多
登录 后发表回答