Archived topic
Add to cart button text
11 replies · Started by Pedro on June 26, 2019
Hello! I would like to change the text of the "add to cart" button for variable products.
I see that Generatepress places the text "Select options", instead of "Add to cart" when a product has variations.
How can I do it?
Thank you!
Hi there,
I believe the first 2 snippets are what you are after:
https://metorik.com/blog/change-the-add-to-cart-text-in-woocommerce
Hi leo! Thanks for answering.
I think I was not specific, I want to change the text to sticky add to cart for variable products.
Since it currently shows "Select options", and I would like it to say "Add to cart"
I'm sorry I did not say it was the sticky add to cart.
The link Leo posted has the answer.
For example:
add_filter( 'woocommerce_product_add_to_cart_text', function( $text ) {
global $product;
$product_type = $product->product_type;
if ( 'variable' === $product_type ) {
$text = 'Add to cart';
}
return $text;
} );
Thank so you mucho Leo and Tom!! You have the best support in the world!!
Glad we could help :)
Hi, I am Looking for similar thing. On my website homepage (https://staging.gartersandco.com.au/)
here is a woocommerce product slider and there SELECT OPTIONS I want to change to BUY NOW.
I tried the snippets from https://metorik.com/blog/change-the-add-to-cart-text-in-woocommerce but these are not working.
function woo_custom_product_add_to_cart_text() {
return __( 'Buy Now', 'woocommerce' );
};
This is changing the text only for 2 products in the slider. Please help.
Any chance you can open a new topic for your question?
Also I don't see Select Options in the product slider in the home page.
Thanks :)
Hi,
I would like to rename the button on the archive pages to "Buy now". For the single products a plugin to make the checkout a onestep process takes care of it, however 2 products are for free, hence it makes no sense naming their button "Buy now", instead of "Download". Unfortunately, I wasn't successful in adjusting the codes offered via the link.
Your help would be greatly appreciated.
Thank you.
Regards
Éva
Hi Éva
Try this:
add_filter( 'woocommerce_product_add_to_cart_text', function( $text ) {
global $product;
if ( $product->is_type( 'variable' ) ) {
$prices = $product->get_variation_prices( true );
$min_price = current( $prices['price'] );
if ( 0 == $min_price ) {
$max_price = end( $prices['price'] );
$min_reg_price = current( $prices['regular_price'] );
$max_reg_price = end( $prices['regular_price'] );
if ( $min_price !== $max_price ) {
$text = 'Download';
} elseif ( $product->is_on_sale() && $min_reg_price === $max_reg_price ) {
$text = 'Download';
} else {
$text = 'Download';
}
}
} elseif ( 0 == $product->get_price() ) {
$text = 'Download';
}
return $text;
} );
Hi Elvin,
worked like a charm! Thank you so much and merry christmas.
Regards
Éva
No problem. :D