Home Forums WoodMart support forum Woo commerce Price to be on the same line as qty and add to cart Reply To: Woo commerce Price to be on the same line as qty and add to cart

#173430

jcbdesign
Participant

Hi Elise,
Thanks for coming back to me. Your video shows what is happening the price of the variation is hidden but the range is still displayed – this is the opposite of what I want to achieve.
In the meantime I’ve got it to do what I wanted. On both single and variable products the price is just above the “add to cart” button, the price range is hidden on variable products and on category pages instead of £123-£456 it’s From £123. The code below goes in the child theme functions php if it’s of help to anyone else. Please note it’s not my original code, but rather pieced together from various sources on the web.
Thanks again.

/**
* Format price range.
*
* @param string $price
* @param float $from
* @param float $to
*
* @return string
*/
function iconic_format_price_range( $price, $from, $to ) {
return sprintf( ‘%s: %s’, __( ‘From’, ‘iconic’ ), wc_price( $from ) );
}

add_filter( ‘woocommerce_format_price_range’, ‘iconic_format_price_range’, 10, 3 );

/**********************************
* Move WooCommerce Price on Single Product Page
* Reference hook locations using 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
************************************/

// Move WooCommerce price
remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 );
add_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 29 );

// don’t show variable price range under title, product pages only
add_filter( ‘woocommerce_variable_sale_price_html’, ‘hide_variable_prices’, PHP_INT_MAX, 2 );
add_filter( ‘woocommerce_variable_price_html’, ‘hide_variable_prices’, PHP_INT_MAX, 2 );
function hide_variable_prices($html) {
if ( is_product() ) {
return ‘<p class=”variable_price”></p>’;
} else {
return $html;
}
}

// show variation price under add-to-cart, even if all variations are the same price
add_filter(‘woocommerce_show_variation_price’, function() {return true;});