WooCommerce shopping cart for WordPress displays the price between the product title and product description on the single product page by default.
If you’d like to move the price after the content, you can do so easily by adding the following hook to your theme’s functions.php file:
[gist id=”acc312ebd7f2ae50c175″ file=”woocommerce-move-price.php”]
The number on each line is the priority. By changing the number from 10 to 25, you move the price below the single excerpt (which has a priority of 20). Changing the number to 35 places the price after the cart button.
The WooCommerce templates/content-single-product.php file shows the hook priorities for the single product loop.
Hi, why do you change woocommerce_single_product_summary to woocommerce_before_single_product_summary ?
Thanks for letting me know about this! I was using the woocommerce_before_single_product_summary hook because I needed to move it outside of the summary wrapper…I forgot to change it back for this article.
woocommerce_single_product_summary works for most applications and allows you to move the price in relation to the hooks shown above, so I’ve corrected to code to reflect that.
Thanks again for the correction!
Nice! Thank you!!
Thanks Sigmareef! Glad you found it helpful.
hi.do i have to add above code to the functions.php file in my active theme. when i did i got “access denied error “
Hi Latheesh,
You can place it in your functions.php file. I just tested it with a clean install using the latest version of WooCommerce and it worked as expected.
I’ve never seen that error so I’m not sure what would cause that. Are you just posting the two lines above (add_action and remove_action)?
hello friend
thanks for the quick response. i am just a beginner :). actually i copy pasted the above code to my functions.php 😉 (but the problem is that those lines are showing up exactly above my website..haha) and i don’t know about whether there is any additional step to be done to achieve the results you have .its really cool 🙂
Hello again. It sounds like you’re missing/misplacing your php tags. You may need to add “<?php" before the code?
If you'd like, paste your code in a pastebin and post the link here and I will take a look:
https://pastebin.com/
works perfect!!!thanks:)
Awesome, glad I could help!
Hi Tony, does this work on a product page with variables?
Hi @marouwing:disqus. It does work with the price range pricing (Price from: $xx.xx to $xx.xx), but not with the price shown when the option is selected, the one above the “add to cart” button.
I have not tried to change the second price location, so I can’t be of much help. I imaging it would be tied into the function that outputs the cart button. I took a quick look but didn’t see it, but that might be a good place to start.
This was a quick fix for me. I was going to go the template route but your solution is much better.
Thank You
Hey @matthewmorisette:disqus so sorry I just saw your comment (a year late hehe). Thanks for the comment and glad it helped! Yes, this way you don’t have to worry about updating other non-related changes done to any templates.
Hello Tony! Thanks a lot for the solution!
It’s finally worked for me, too. I’ve surfed all over the Net to fix it… After another update of woocommerce (3), I’ve noticed the price of non variative product is missing at the single product page, while it’s shown at the list of products page , as well as it’s shown for variative products both at the list page and the single product page. I’ve added the code you’d kindly shared above to my wp-content/themes/my_theme_directory/functions.php file , et voila! Thank you so much!!!
Hello Tony! Thanks a lot for the solution!
It’s finally worked for
me, too. I’ve surfed all over the Net to fix it… After another update
of woocommerce (3), I’ve noticed the price of non variative product is
missing at the single product page, while it’s shown at the list of
products page , as well as it’s shown for variative products both at the
list page and the single product page. I’ve added the code you’d kindly
shared above to my wp-content/themes/my_theme_directory/functions.php file , et voila! Thank you so much!!!
Hi @olgadjirikova:disqus thank you for your nice comment! I’m glad to hear it worked…wasn’t sure after their latest major update (which broke a lot of things).
Thank you 🙂
The price has a priority of 10, the excerpt has a priority of 20. To swap them around, change the priorities by modifying the actions in your child theme’s functions.php.
remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 );
remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_excerpt’, 20 );
add_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_excerpt’, 10 );
add_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 20 );