/**
 * Change the add to cart text on single product pages
 */
add_filter('woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text');
function woo_custom_cart_button_text() {
	
	foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
		$_product = $values['data'];
	
		if( get_the_ID() == $_product->get_id() ) {
			return __('Already in cart - Add Again?', 'woocommerce');
		}
	}
	
	return __('Add to cart', 'woocommerce');
}
/**
 * Change the add to cart text on product archives
 */
 
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_archive_custom_cart_button_text' );
function woo_archive_custom_cart_button_text() {
	
	global $product;

    $product_type = $product->get_type();
	
	if( $product->is_type( 'simple' ) ){

	      foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
	    	 $_product = $values['data'];
	
	    	 if( get_the_ID() == $_product->get_id() ) {
	    		return __('Already in cart', 'woocommerce');
		    }
	    }
	
	    return __('Add to cart', 'woocommerce');
     }
     else {

     switch ( $product_type ) {
       
        default:
            return __( 'Read more', 'woocommerce' );
        }
    } 
}

Odgovori

Vaša email adresa neće biti objavljena. Obavezna polja su označena s *

Komentiraj