John Franky John Franky - 5 months ago 17
PHP Question

Sample Product, change location of Price | Wordpress Woocommerce

I am trying to change the location of Price of all sample Products from the current location, which is below the title to just about "add to cart".

If i do it with CSS, that is affecting the responsiveness of the website.

i want to make this change on a PHP, so that it can impact all the SAMPLE products which i upload now on..

can i make any changes on the PHP so that the "SAMPLE Product" Price always shows up just above "add to cart" ?

at present:

enter image description here

what i need is:

enter image description here

the code in content-single-product.php

<div class="single clearfix row-fluid">
<div class="wrap span6 product-left">
<?php
/**
* woocommerce_show_product_images hook
*
* @hooked woocommerce_show_product_sale_flash - 10
* @hooked woocommerce_show_product_images - 20
*/
do_action( 'woocommerce_before_single_product_summary' );
?>
</div>
<div class="span6">
<div class="product-detail">
<?php
/**
* woocommerce_single_product_summary hook
*
* @hooked woocommerce_template_single_title - 5
* @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' );
//echo do_shortcode("[yith_wcwl_add_to_wishlist]");
?>
</div>
</div>
</div>

Answer

In the below code, you are overwriting the WooCommerce hook inclusion/priority order. So the price will be included after woocommerce_template_single_excerpt which has a priority value of 20

Include the following code in functions.php.

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );

add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 25 );