Skip to content

Instantly share code, notes, and snippets.

@kontikidigital
Last active January 14, 2021 09:42
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save kontikidigital/b92dbf2ebde2bc5e54e8967f9bf7d149 to your computer and use it in GitHub Desktop.
Save kontikidigital/b92dbf2ebde2bc5e54e8967f9bf7d149 to your computer and use it in GitHub Desktop.
WooCommerce: Change Select Options Button Text for variable products
add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );
/**
* custom_woocommerce_template_loop_add_to_cart
*/
function custom_woocommerce_product_add_to_cart_text() {
global $product;
$product_type = $product->get_type();
switch ( $product_type ) {
case 'external':
return __( 'Buy product', 'woocommerce' );
break;
case 'grouped':
return __( 'View products', 'woocommerce' );
break;
case 'simple':
return __( 'Add to cart', 'woocommerce' );
break;
case 'variable':
return __( 'Select options', 'woocommerce' );
break;
default:
return __( 'Read more', 'woocommerce' );
}
}
@pebblemarketing
Copy link

Do i add this to the file or is this code there and the text just needs to edited? Where do I find this file?

@kontikidigital
Copy link
Author

You need to add this code in your child theme to functions.php

@ryananthonydrake
Copy link

This is a lifesaver - thank you!

@NewMarketMedia
Copy link

Brilliant! Thank you!

@napathello
Copy link

problem get type , please use

$product_type = $product->get_type();

@sudopower
Copy link

Perfect !

@Cristilupchian
Copy link

This is working beautifully, thank you!

@Avadhutch50
Copy link

I have woocommerce Combo Offer product, and this code is not changing text for combo product! pls help

@creativetoria
Copy link

Thank you. Perfect!

@kontikidigital
Copy link
Author

problem get type , please use

$product_type = $product->get_type();

Thanks, I've updated this gist including your suggestion.

@kontikidigital
Copy link
Author

I have woocommerce Combo Offer product, and this code is not changing text for combo product! pls help

Sorry, I don't know Combo Offer product, maybe this plugin is modifying woocommerce_product_add_to_cart_text filter or something like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment