-
-
Save mihdan/a9abc1a0c158cb1fff39 to your computer and use it in GitHub Desktop.
WooCommerce - Product already in cart, change "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 | |
/** | |
* 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'); | |
add_filter( 'add_to_cart_text', 'woo_custom_cart_button_text' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment