Skip to content

Instantly share code, notes, and snippets.

@farookibrahim
Created July 7, 2020 04:46
Show Gist options
  • Select an option

  • Save farookibrahim/3903458a002a14602e81d4c1adc4a914 to your computer and use it in GitHub Desktop.

Select an option

Save farookibrahim/3903458a002a14602e81d4c1adc4a914 to your computer and use it in GitHub Desktop.
WooCommerce - Custom "Add to cart" text
function woocommerce_custom_product_add_to_cart_text( $text, $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' );
}
}
add_filter( 'woocommerce_product_add_to_cart_text' , 'woocommerce_custom_product_add_to_cart_text', 20, 2 );
function woocommerce_custom_product_single_add_to_cart_text( $text, $product ) {
return __( 'Add to cart', 'woocommerce' );
}
add_filter( 'woocommerce_product_single_add_to_cart_text' , 'woocommerce_custom_product_single_add_to_cart_text', 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment