Support » Plugin: WooCommerce » How to hide/disable add to cart button if a specific attribute is selected

  • Resolved stan255

    (@stan255)


    How to hide/disable add to cart button if a specific attribute is selected?

    This is the specific attribute.

    <li data-wvstooltip="Need it faster? Contact Us" class="variable-item button-variable-item button-variable-item-need-it-faster-contact-us" title="Need it faster? Contact Us" data-value="Need it faster? Contact Us"><span class="variable-item-span variable-item-span-button">Need it faster? Contact Us</span></li>

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Could you not set this attribute to Manage Stock and the stock status to Out Of Stock?

    Thread Starter stan255

    (@stan255)

    @seank123 Thanks for the reply. That won’t work for us because we are using a Swatch plugin which cancels out the option if there is no stock.

    Thread Starter stan255

    (@stan255)

    That’s a good link! I gave it a shot but I can’t get it to work with attributes with text only.

    It works with attributes with numbers but not with text. For some odd reason.


    add_filter('woocommerce_variation_is_purchasable', 'conditional_variation_is_purchasable', 20, 2);

    function conditional_variation_is_purchasable($purchasable, $product) {
    $taxonomy = 'pa_height';
    $term_name = '4.1m';

    $found = false;

    foreach($product->get_variation_attributes() as $variation_attribute => $term_slug) {
    $attribute_taxonomy = str_replace('attribute_', '', $variation_attribute); // The taxonomy
    $term = get_term_by('slug', $term_slug, $taxonomy);
    if($attribute_taxonomy == $taxonomy && $term->name == $term_name) {
    $found = true;
    break;
    }
    }

    if($found)
    $purchasable = false;

    return $purchasable;
    }

    Plugin Support Mike W

    (@nixiack8)

    Hi @stan255,

    This may be due to an override with your theme, as the code checks out and should work with base WooCommerce. Have you reached out to your theme provider to see if there is an override, or conflict tested by doing the following?

    1. Temporarily switch your theme back to the Storefront or Twenty Seventeen Theme. Place the code in the functions.php file of that theme.
    2. Disable all plugins except for WooCommerce and your payment/shipping gateways.
    3. Test to see if the issue has been resolved.

    If that resolves the issue, then one-by-one you can switch back your theme and re-enable your plugins, testing in between, until you find the one causing the conflict. If it is your theme you can reach out to your theme providers.

    Let us know how it goes!

    Plugin Support Mike W

    (@nixiack8)

    Hi @stan255,

    I am going to close this thread for now, however if you are still having the issue just reply to this and we will re-open it.

    If you have other issues please open a new thread and let us know!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to hide/disable add to cart button if a specific attribute is selected’ is closed to new replies.