Variation swatches disable quantity box and hide some text

Solved6 replies2 participantsUpdated by Deborah

  • Avatar: Deborah
    Deborah
    Participant

    Hi,
    I’ve got many issues with variations swatches.
    – I would like to hide clear button (because there’s always something selected)
    – I would like to hide also label button (like size, color etc. to make it more minimalist)
    – Most of all : I don’t want a quantity box
    – Most of all all : I’ve entered this code (see text under) in function.php so that price goes in add to cart button, it works perfectly for shop page but not for single product page 😭 :

    add_filter( ‘woocommerce_product_add_to_cart_text’, ‘custom_add_to_cart_price’, 20, 2 ); // Shop and other archives pages
    add_filter( ‘woocommerce_product_single_add_to_cart_text’, ‘custom_add_to_cart_price’, 20, 2 ); // Single product pages
    function custom_add_to_cart_price( $button_text, $product ) {
    // Variable products
    if( $product->is_type(‘variable’) ) {
    // shop and archives
    if( ! is_product() ){
    $product_price = wc_price( wc_get_price_to_display( $product, array( ‘price’ => $product->get_variation_price() ) ) );
    return $button_text . ‘ – ‘ . strip_tags( $product_price );
    }
    // Single product pages
    else {
    return $button_text;
    }
    }
    // All other product types
    else {
    $product_price = wc_price( wc_get_price_to_display( $product ) );
    return $button_text . ‘ – ‘ . strip_tags( $product_price );
    }
    }

    Thanks for your help 🙏🏽
    Have a nice day,
    Take care,

    Deborah

    Files is visible for topic creator and
    support staff only.

    6 Answers

    Avatar: Justin
    Luca Rossi
    Support staff

    Hi @Deborah,

    Please try adding this custom CSS under XStore > Theme Options > Theme Custom CSS > Global CSS:

    
    .single-product .woocommerce-variation.single_variation,
    .single-product a.reset_variations,
    .single-product .woocommerce-variation-add-to-cart .quantity {
        display: none !important;
    }
    

    https://prnt.sc/d-gxKDrY743B

    Kind regards,
    The 8Theme Team

    Avatar: Deborah
    Deborah
    Participant

    Hi Luca,
    thanks it works in previsualisation mode but not in administration but important is that for client it looks like this.

    I still have the other problems :

    I’ve entered this code (see text under) in function.php so that price goes in add to cart button, it works perfectly for shop page but not for single product page 😭 :

    add_filter( ‘woocommerce_product_add_to_cart_text’, ‘custom_add_to_cart_price’, 20, 2 ); // Shop and other archives pages
    add_filter( ‘woocommerce_product_single_add_to_cart_text’, ‘custom_add_to_cart_price’, 20, 2 ); // Single product pages
    function custom_add_to_cart_price( $button_text, $product ) {
    // Variable products
    if( $product->is_type(‘variable’) ) {
    // shop and archives
    if( ! is_product() ){
    $product_price = wc_price( wc_get_price_to_display( $product, array( ‘price’ => $product->get_variation_price() ) ) );
    return $button_text . ‘ – ‘ . strip_tags( $product_price );
    }
    // Single product pages
    else {
    return $button_text;
    }
    }
    // All other product types
    else {
    $product_price = wc_price( wc_get_price_to_display( $product ) );
    return $button_text . ‘ – ‘ . strip_tags( $product_price );
    }
    }

    Avatar: Justin
    Luca Rossi
    Support staff

    Dear @Deborah,

    Please try with this custom code instead:

    
    add_filter( 'woocommerce_product_add_to_cart_text', 'custom_add_to_cart_price', 999, 2 ); // Shop and other archives pages
    add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_add_to_cart_price', 999, 2 ); // Single product pages
    function custom_add_to_cart_price( $button_text, $product ) {
    	if( $product->is_type('variable') ) {
    		$product_price = wc_price( wc_get_price_to_display( $product, array( 'price' => $product->get_variation_price() ) ) );
    		return $button_text . ' – ' . strip_tags( $product_price );
    	} else {
    		$product_price = wc_price( wc_get_price_to_display( $product ) );
    		return $button_text . ' – ' . strip_tags( $product_price );
        }
    }
    

    Hope it helps!

    Avatar: Deborah
    Deborah
    Participant

    Hi Luca,

    It helps a little. But I’ve got issues :
    1) it doesn’t return the good price when I select another variation. It always return the minimum price.
    2) on shop page, the little icon add to cart is not in the circle anymore.

    Files is visible for topic creator and
    support staff only.
    Avatar: Justin
    Luca Rossi
    Support staff

    Dear @Deborah,

    1. It would require many customization codes to achieve this function and fall out of scope our support standard services we provide. If you would prefer professional assistance, our development team offers customization services. You are welcome to submit a request via our Customization Panel at: https://www.8theme.com/account/#etheme_customization_panel. Kindly be advised that such services may incur additional charges.

    2. Please try adding this custom CSS under XStore > Theme Options > Theme Custom CSS > Global CSS:

    
    .etheme-product-grid-item .footer-inner .button {
        text-indent: -9999px;
    }
    

    Kind regards,
    The 8Theme Team

    Avatar: Deborah
    Deborah
    Participant

    Thanks for the support! My topic “Variation swatches disable quantity box and hide some text” has been successfully resolved.

The issue related to '‘Variation swatches disable quantity box and hide some text’' has been successfully resolved, and the topic is now closed for further responses