Custom php code to stop user from deselecting or clearing variants

This topic has 4 replies, 2 voices, and was last updated 12 months ago ago by Andrew Mitchell

  • Avatar: ZEXAL
    ZEXAL
    Participant
    December 22, 2024 at 10:48

    What the title says. I want to stop user from deselecting product variants when he clicks on a product variant. Basically, a variant is always selected and he can’t clear it. I found php code online that worked on dropdown menus but not swatches.

    3 Answers
    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    December 23, 2024 at 17:57

    Hello, ZEXAL,

    Thank you for reaching out to us. Kindly try adding the following code to:
    Customizer -> Theme Custom CSS -> Global CSS.

    .st-swatch-preview-single-product .selected{
    	pointer-events:none;
    }
    a.reset_variations{
        display:none!important;
    }

    Best regards,
    The 8Theme Team

    Avatar: ZEXAL
    ZEXAL
    Participant
    December 24, 2024 at 17:20

    This part won’t work:

    a.reset_variations{
        display:none!important;
    }

    for anyone reading this and want to get rid of the clear button, add the following code to your functions.php in your child theme folder:
    add_filter( 'woocommerce_reset_variations_link', '__return_empty_string', 9999 );

    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    December 24, 2024 at 17:21

    Dear ZEXAL,

    Choosing our theme reflects your commitment to quality, and for that, we’re genuinely grateful. As we constantly strive to elevate your experience, your feedback is an invaluable gift. Could you kindly take a moment to rate our product with 5 stars on ThemeForest?

    Click here to share your insights: https://themeforest.net/downloads

    Your support fuels our journey, and we appreciate it more than words can express.

    Best Regards,
    The 8Theme Team

  • Viewing 4 results - 1 through 4 (of 4 total)

The issue related to '‘Custom php code to stop user from deselecting or clearing variants’' has been successfully resolved, and the topic is now closed for further responses

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.