Skip to content

Instantly share code, notes, and snippets.

@acanza
Created June 21, 2016 15:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save acanza/2874c67f3099909e4f2e196c9c9165ee to your computer and use it in GitHub Desktop.
Save acanza/2874c67f3099909e4f2e196c9c9165ee to your computer and use it in GitHub Desktop.
Avisa si un producto ya está en el carro
/**
* Cambia el texto del botón añadir al carro en la página del producto
*/
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'];
if( get_the_ID() == $_product->id ) {
return __('Ya está en el carro - ¿Añadir otro?', 'woocommerce');
}
}
return __('Add to cart', 'woocommerce');
}
/**
* Cambia el texto del botón añadir al carro en la página del catálogo
*/
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_archive_custom_cart_button_text' );
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 __('Ya está en el carro', 'woocommerce');
}
}
return __('Add to cart', 'woocommerce');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment