Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MinaPansuriya/2810782ffa5fa61afbf8479195073fe5 to your computer and use it in GitHub Desktop.
Save MinaPansuriya/2810782ffa5fa61afbf8479195073fe5 to your computer and use it in GitHub Desktop.
/**
* @Title: WooCommerce Change Add to Cart Button Text for particular product type on Single Product Page
* @Author: Mina Pansuriya
* @Website: http://minapansuriya.com
*/
add_filter( 'woocommerce_product_single_add_to_cart_text', 'pbs_change_single_product_add_to_cart_text', 2, 99 );
function pbs_change_single_product_add_to_cart_text($dflt_add_to_cart_text, $product) {
$product_type = $product->product_type;
// Get the product type
switch ( $product_type ) {
case 'external':
return __( 'Buy on Amazon', 'woocommerce' );
case 'grouped':
return __( 'Buy Now', 'woocommerce' );
case 'simple': // Simple, Virtual, Downloadable Product
return __( 'Buy Now', 'woocommerce' );
case 'variable':
return __( 'Buy Now', 'woocommerce' );
}
return $dflt_add_to_cart_text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment