Skip to content

Instantly share code, notes, and snippets.

@Bradley-D
Forked from corsonr/gist:6775121
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bradley-D/8843345 to your computer and use it in GitHub Desktop.
Save Bradley-D/8843345 to your computer and use it in GitHub Desktop.
/**
* Change the add to cart text on single product pages
*/
function woo_custom_cart_button_text() {
global $woocommerce;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if( get_the_ID() == $_product->id ) {
return __( 'Already in cart - Add Again?', 'woocommerce' );
}
}
return __( 'Add to cart', 'woocommerce' );
}
add_filter( 'single_add_to_cart_text', 'woo_custom_cart_button_text' );
/**
* Change the add to cart text on product archives
*/
function woo_archive_custom_cart_button_text() {
global $woocommerce;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if( get_the_ID() == $_product->id ) {
return __( 'Already in cart', 'woocommerce' );
}
}
return __('Add to cart', 'woocommerce');
}
add_filter( 'add_to_cart_text', 'woo_archive_custom_cart_button_text' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment