Skip to content

Instantly share code, notes, and snippets.

@digiltd
Forked from jameskoster/gist:7691051
Last active August 29, 2015 14:02
Show Gist options
  • Save digiltd/07b0069a6f012d2411e6 to your computer and use it in GitHub Desktop.
Save digiltd/07b0069a6f012d2411e6 to your computer and use it in GitHub Desktop.
change add to cart button text based on purchase and add product quantity to button text
<?php
//Change add to cart button text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' );
function woo_custom_cart_button_text() {
global $woocommerce;
foreach($woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
$_quantity = $values['quantity'];
if( get_the_ID() == $_product->id ) {
return __('Already in cart - Add Again? '.$_quantity, , 'woocommerce');
}
}
return __('Add to cart', 'woocommerce');
}
//Change add to cart button text on archive-product (shop)
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_archive_custom_cart_button_text' ); // 2.1 +
function woo_custom_cart_button_text() {
global $woocommerce;
foreach($woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
$_quantity = $values['quantity'];
if( get_the_ID() == $_product->id ) {
return __('Ordered '.$_quantity, 'woocommerce');
}
}
return __('Add to order', 'woocommerce');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment