Skip to content

Instantly share code, notes, and snippets.

@woogist
Last active June 8, 2020 23:11
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save woogist/1128a0803928edc4bd0f to your computer and use it in GitHub Desktop.
WooCommerce: change "add to cart" button text by product type
<?php
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->product_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' );
}
}
@alo123YCA
Copy link

Hi,
I tried this css on my function.php and it blank my entire website. I no longer have access to my site. Can you please help me?

@icemancast
Copy link

Most likely you have a php error that your production site will not parse because it's on production. Remove this code and reload your site. I believe this is outdated code and no longer works.

@icemancast
Copy link

@DaniEM1
Copy link

DaniEM1 commented Jun 8, 2020

Where can I find this file?

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