Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save icemancast/d94c2fcfe5ccf073330aab4a7d55765b to your computer and use it in GitHub Desktop.
Save icemancast/d94c2fcfe5ccf073330aab4a7d55765b 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->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' );
}
}
@DaniEM1
Copy link

DaniEM1 commented Jun 8, 2020

This helped me a lot, thank you !

@icemancast
Copy link
Author

Awesome glad to hear.

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