Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save MinaPansuriya/8792865609b5a5a339b61827ccd13ae6 to your computer and use it in GitHub Desktop.

Select an option

Save MinaPansuriya/8792865609b5a5a339b61827ccd13ae6 to your computer and use it in GitHub Desktop.
/**
* @Title: WooCommerce Change Add to Cart Button Text for particular product type on Shop/Category Page
* @Author: Mina Pansuriya
* @Website: http://minapansuriya.com
*/
add_filter( 'woocommerce_product_add_to_cart_text' , 'pbs_woo_change_add_to_cart_button_text', 2, 99 );
function pbs_woo_change_add_to_cart_button_text($dflt_add_to_cart_text, $product) {
// Get the product type
$product_type = $product->product_type;
switch ( $product_type ) {
case 'grouped':
return __( 'View Products', 'woocommerce' );
case 'simple': // Simple, Virtual, Downloadable Product
return __( 'Buy Now', 'woocommerce' );
case 'variable':
return __( 'Select options', '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