custom_add_to_cart_button_text( 'single', $add_to_cart_text ); } /** * custom_add_to_cart_button_text_archives. * * @version 1.2.0 * @since 1.2.0 */ function custom_add_to_cart_button_text_archives( $add_to_cart_text ) { return $this->custom_add_to_cart_button_text( 'archives', $add_to_cart_text ); } /** * get_custom_label_value. * * @version 1.2.0 * @since 1.2.0 */ function get_custom_label_value( $single_or_archives, $product_type, $condition ) { return get_option( 'alg_wc_add_to_cart_p_prod_type_on_' . $single_or_archives . $condition . '_' . $product_type, '' ); } /** * custom_add_to_cart_button_text. * * @version 1.2.0 * @since 1.0.0 * @todo [feature] variable products: per variation, e.g. "already in cart" for single view */ function custom_add_to_cart_button_text( $single_or_archives, $add_to_cart_text ) { global $product; if ( ! $product ) { return $add_to_cart_text; } $product_type = alg_wc_atcbl_get_product_type( $product ); if ( ! in_array( $product_type, array( 'external', 'grouped', 'simple', 'variable' ) ) ) { $product_type = 'other'; } // Already in Cart if ( '' != ( $label = $this->get_custom_label_value( $single_or_archives, $product_type, '_in_cart' ) ) && isset( WC()->cart ) ) { foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { $_product = $values['data']; if ( get_the_ID() == alg_wc_atcbl_get_product_or_variation_parent_id( $_product ) ) { return $label; } } } // Empty Price if ( '' != ( $label = $this->get_custom_label_value( $single_or_archives, $product_type, '_no_price' ) ) && '' === $product->get_price() ) { return $label; } // Zero Price if ( '' != ( $label = $this->get_custom_label_value( $single_or_archives, $product_type, '_zero_price' ) ) && '0' === $product->get_price() ) { return $label; } // On sale if ( '' != ( $label = $this->get_custom_label_value( $single_or_archives, $product_type, '_on_sale' ) ) && apply_filters( 'alg_wc_add_to_cart_button_labels', false, 'value_on_sale', array( 'product' => $product ) ) ) { return $label; } // Normal Price return ( '' != ( $label = $this->get_custom_label_value( $single_or_archives, $product_type, '' ) ) ) ? $label : $add_to_cart_text; } } endif; return new Alg_WC_Add_To_Cart_Button_Labels_Per_Product_Type();