Website Building » WooCommerce » How Do I Remove Select Options in WooCommerce?

How Do I Remove Select Options in WooCommerce?

Last updated on December 23, 2022 @ 4:56 pm

When you are running a WooCommerce store, there are times when you may need to remove certain select options from products. For example, you may want to disable certain color or size options if they are no longer available. In this article, we will show you how to remove select options in WooCommerce.

First thing you need to do is login to your WordPress Dashboard and go to WooCommerce > Settings. On the Settings page, click on the Products tab and then on the inventory link. This will take you to the inventory settings page.

On the inventory settings page, you need to scroll down to the Out of Stock Visibility section. By default, WooCommerce will hide out of stock items from your shop pages and search results.

However, we recommend that you set this option to < >Don’t hide out of stock items from the shop. This way, customers will be able to see what products are available and what options they have.

Now that Out of Stock Visibility is set, let’s move on to removing select options in WooCommerce.

Method 1: Remove Select Options Using the WP_Query Class

The first method we’re going to look at is using the WP_Query class. This method is fairly simple and only requires a few lines of code.

PRO TIP: If you are using WooCommerce to manage your online store, you may want to remove some of the select options that are available to your customers. This can be done by going to the WooCommerce settings page and selecting the “Remove Select Options” tab.

However, before you remove any of the select options, you should first consider whether or not doing so will impact your customers’ ability to purchase your products. If you remove too many options, it could make it difficult for customers to find the products they are looking for.

Additionally, you should also be aware that removing select options could also impact your search engine optimization (SEO) efforts. If you remove options that are popular keywords, it could result in a drop in your search engine rankings.

$args = array(  
'post_type' => 'product',   
'posts_per_page' => -1,   
'meta_query' => array(     
array(       
'key' => '_stock_status',       
'value' => 'outofstock',       
'compare' => 'NOT IN'     
)   
) 
); 
$query = new WP_Query( $args ); while ( 
$query->have_posts() ) {   
$query->the_post();   
// Get product object    
$product = wc_get_product( get_the_ID() );    
// Get product type    
$type = $product->get_type();      
switch ( $type ) {     
case "variable" :        
// Get product variations       
$variations = $product->get_available_variations();        
foreach ( $variations as $key =& $value ) {          
// Check if variation is in stock           
if ( !$value['is_in_stock'] ) {             
// Remove variation from product            
unset( $product->variation_data[$key] );           
}         
}      
break;     
case "grouped" :        
// Get grouped products       
$groupedProducts = $product->get_children();        
foreach ( $groupedProducts as $childID ) {          
// Get child product          
$_childProduct = wc_get_product( $childID );           
// Check if child product is in stock           
if ( !$childProduct->is_in_stock() ) {             
// Remove child product from grouped product            
unset( $_childProduct );           
}         
}      
break;    
}   
} wp_reset_postdata();
  1. “Grouped Products”: If you’re using grouped products, then this code will remove any child products that are out of stock.
  2. “Variable Products”: If you’re using variable products, then this code will remove any variations that are out of stock.

Method 2: Remove Select Options Using the .woocommerce-outofstock Class

Another way that you can remove select options in WooCommerce is by using CSS. In particular, you can Target the .woocommerce-outofstock class which is applied to out of stock variations.

.WooCommerce ul.products li.product 
.woocommerce-variation 
.woocommerce-variation-select{ display:none !important;} 
.woocommerce-variation{ display:none !important;} 

Method #3 – Remove Select Options Using.wc-variations table

  • Another way that you can remove select options in WooCommerce is by using CSS.wc-variations table.
  • This method only works for grouped products.wc= variactions table
  • By Targeting this element, we can hide all of the variation selectors. This method only works for grouped products.
.wc= variactions table{display:none !important;}

This CSS code will hide all variation selectors on your site. If you want to Target specific products or groups of products, then you will need to use a more specific selector. For example, if we wanted to Target all variable product pages, we could use this CSS selector:

< pre class=”wp block preformatted”> li.product .wc variactions table {display:none !important;} / pre >

This would hide all variation selectors on your site’s variable product pages. This method only works for grouped products while leaving other pages unaffected.

You can also use the same technique to Target specific groups of products. For example, let’s say that we wanted to Target all variable product pages with a specific attribute value. We could use this CSS selector:

.< pre class=”wp block preformatted”> li.product[class*=”color”] .wc variactions table {display:none !important;} / pre >

This would hide all variation selectors on your site’s variable product pages with the “color” attribute while leaving other pages unaffected.

You can learn more about CSS selectors and how they work in our comprehensive guide on CSS selectors.

Dale Leydon

Dale Leydon

Sysadmin turned Javascript developer. Owner of 20+ apps graveyard, and a couple of successful ones.