Created
July 25, 2020 11:46
-
-
Save deeman/dbfddbde316ce11187093d3210f454e4 to your computer and use it in GitHub Desktop.
WooCommerce: Change the Add to Cart text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//For the ‘single’ product page, let’s add the following: | |
// Change 'add to cart' text on single product page | |
add_filter( 'woocommerce_product_single_add_to_cart_text', 'bryce_add_to_cart_text' ); | |
function bryce_add_to_cart_text() { | |
return __( 'Yes! I WANT this!', 'your-slug' ); | |
} | |
//But then what about on the ‘archive’ product pages? Add this: | |
// Change 'add to cart' text on archive product page | |
add_filter( 'woocommerce_product_add_to_cart_text', 'bryce_archive_add_to_cart_text' ); | |
function bryce_archive_add_to_cart_text() { | |
return __( 'YES! I NEED this!', 'your-slug' ); | |
} | |
// Change add to cart text on archives depending on product type | |
add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' ); | |
function custom_woocommerce_product_add_to_cart_text() { | |
global $product; | |
$product_type = $product->product_type; | |
switch ( $product_type ) { | |
case 'external': | |
return __( 'Take me to their site!', 'woocommerce' ); | |
break; | |
case 'grouped': | |
return __( 'VIEW THE GOOD STUFF', 'woocommerce' ); | |
break; | |
case 'simple': | |
return __( 'WANT. NEED. ADD!', 'woocommerce' ); | |
break; | |
case 'variable': | |
return __( 'Select the variations, yo!', 'woocommerce' ); | |
break; | |
default: | |
return __( 'Read more', 'woocommerce' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment