Home Forums Plugins WooCommerce Product Variations Swatches Feature Addition: Hide not purchasable Attributes

Feature Addition: Hide not purchasable Attributes

  • Author
  • #109283


    i know that there is the feature that hides not “available” attribute options but if I want to show all attributes that are used by purchasable items but want to hide attributes that are only used by disabled or out of stock variations there is no option.

    I will attach my solution to it, its actually just a filter for the used terms. Code Lines 459 – 472 in the attached frontend.php

    Please let me know what you think about it an in the best case implement it so that i don’t have to rewrite your “core” plugin files 🙂

    EDIT – Unfortunately i can’t upload a php file so i added it as txt file.
    EDIT – EDIT .. also not possible.. will add the code here then and a screenshot…

    			$variations = $product->get_children();
    			if ( taxonomy_exists( $attribute ) ) {
    				$terms = wc_get_product_terms(
    						'fields' => 'all',
                    $filteredTerms = [];
                    $productVariations = $product->get_available_variations();
                    foreach ( $terms as $term ) {
                        foreach ($productVariations as $variation) {
                            if ($variation["is_purchasable"] &&
                                $variation["is_in_stock"] &&
                                $variation["attributes"]["attribute_" . $attribute] == $term->slug
                                $filteredTerms[] = $term;
                                break; // to prevent duplicate entries and unnecessary runs
                    $terms = $filteredTerms;
    				switch ( $type ) {
    You must be logged in to view attached files.

You must be logged in to see replies to this topic. Click here to login or register