Plugin Support
Hannah S.L.
(@fernashes)
Automattic Happiness Engineer
Here’s a good guide on how to re-order the single product page – that should help you in the right direction:
https://wisdmlabs.com/blog/reorder-content-woocommerce-product-page/
Yes, I found this or a very similar page, reordered my php but there’s no change in the result. I saved the single-product.php file to the woocommerce directory inside my child-theme directory, as another place suggested, to keep it from being overwritten when WooCommerce is updated. Is there a better place to locate that file?
Hi @janburg,
Any add_action() or remove_action() code as described within the tutorial Hannah linked to should be added to a themes functions.php file and you should not perform any edits to the actual single-product.php itself.
I copied the rearranged order for the single_product summary hook to the child functions.php file, still no change in order. I rearrange, test, rearrange, but to no result. And yes, I am clearing cache.
It sounds like you don’t have the right approach here. There’s no need to copy content-single-product.php and edit it.
The page is made up of a series of sections. The position of each section is defined by a hook and a priority. You can’t move a section in one go, the technique is to remove it from one place and then put it back in another.
For example, let’s move the meta section to after the image. Firstly remove it using a remove_action(). Note that in remove_action(), the priority parameter must be the same as the original add_action(). So:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
You can get the hook, the section callback function name and the priority from content-single-product.php.
Next, put it back in the page, but this time put it after the image with:
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_template_single_meta', 30 );
With enough pairs of remove_action() and add_action(), the page sections can be comprehensively reordered. Ultimately swapping left to right is possible.
This code goes in functions.php for your child theme, or, if you don’t have a child theme you can use the “My Custom Functions” plugin.
Ok, I did what you said, removed then added a line, but there still is no change.
<div class="summary entry-summary">
<?php
//* to change the position of excerpt
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 65 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_template_single_meta', 30 );
?>
</div><!-- .summary -->
<?php }
Do I have the <?php and ?> in the right place? There is more code under this, for a custom footer, so the last <?php would be for that code, correct?
This should be all php code, so no html or php tags should be in there. The code goes in functions.php for your child theme or you can use the “My Custom Functions” plugin. Don’t edit the template. If you might have edited the template, replace with a fresh copy.
Ok, removed the div class, which I had copied over from the content-single-product.php. I guess I need to read up on the </php and ?> tags, since when I remove them from the functions.php file I get an error from Dreamweaver (using that only as a text editor).
functions.php will have <?php on the first line.
You might see other html code in functions.php inside functions but if so it will be surrounded by tags:
function my_func() {
?>
<p>Text</p>
<?php
}
Your series of removes and adds won’t have their own tags.
WordPress practice is that there is no closing ?> at the end of the document.
Yeah, I figured out that there was a close tag just before some <script> then another <?php tag after the script to go back to php. But that still hasn’t made a difference in my layout.
Well the guidance is based on a default theme. Please try with the Twenty Seventeen theme. That should work. Please say what happens.
I’m using the Genesis Frameworks theme, don’t really want to switch themes at this point. But it would be an interesting exercise.
Not good, fatal error on the singe product page: “Fatal error: Uncaught Error: Call to undefined function genesis() in /homepages/46/d691376626/htdocs/clickandbuilds/RadicalUrge/wp-content/plugins/genesis-connect-woocommerce/templates/single-product.php:85 Stack trace: #0 /homepages/46/d691376626/htdocs/clickandbuilds/RadicalUrge/wp-includes/template-loader.php(74): include() #1 /homepages/46/d691376626/htdocs/clickandbuilds/RadicalUrge/wp-blog-header.php(19): require_once(‘/homepages/46/d…’) #2 /homepages/46/d691376626/htdocs/clickandbuilds/RadicalUrge/index.php(17): require(‘/homepages/46/d…’) #3 {main} thrown in /homepages/46/d691376626/htdocs/clickandbuilds/RadicalUrge/wp-content/plugins/genesis-connect-woocommerce/templates/single-product.php on line 85
line 85 is ‘genesis();’ I have not changed that page at all. curiouser and curiouser.
I’m suggesting a temporary theme switch to see if the removes and adds work. If not, deactivate all other plugins. If it works now, switch theme and plugins back one-by-one to try to identify what’s causing the hooks to fail. We can move forward from there.
aarrgghh! went to update some plugins, now it’s stuck on the “Briefly unavailable for scheduled maintenance. Check back in a minute.” page.
There’s only so much headpounding I can take in one day.
@janburg
if it is stuck on that just look for a .maintenance file at the root of the site. You can just delete this file and the admin will come back. It gets set during plugin updates so functions do not get called which would break the site if it attempts to load them.