Answer the question
In order to leave comments, you need to log in
Woocommerce display price in "add to cart" button?
How to display the price in the Add to Cart button in Woocommerce?
Answer the question
In order to leave comments, you need to log in
The code needs to be added to function.php:
add_filter( 'woocommerce_product_add_to_cart_text', 'custom_add_to_cart_price', 20, 2 ); // Shop and other archives pages
add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_add_to_cart_price', 20, 2 ); // Single product pages
function custom_add_to_cart_price( $button_text, $product ) {
if( $product->is_type('variable') ) { // Variable products
if( ! is_product() ){ // shop and archives
$product_price = wc_price( wc_get_price_to_display( $product, array( 'price' => $product->get_variation_price() ) ) );
return $button_text . ' - From ' . strip_tags( $product_price );
} else { // Single product pages
return $button_text;
}
} else { // All other product types
$product_price = wc_price( wc_get_price_to_display( $product ) );
return $button_text . ' - Just ' . strip_tags( $product_price );
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question