Skip to content

Instantly share code, notes, and snippets.

@rubel306
Last active March 16, 2019 16:20
Show Gist options
  • Save rubel306/e5e191034e77bc07ad86dd62401a0a07 to your computer and use it in GitHub Desktop.
Save rubel306/e5e191034e77bc07ad86dd62401a0a07 to your computer and use it in GitHub Desktop.
Woocommerce functions
//change woocommerce columns number
function theme_name_woocommerce_loop_shop_columns($nc){
return 3; //number of columns here
}
add_filter("loop_shop_columns", "theme_name_woocommerce_loop_shop_columns");
//exclude/hide/remove woocommerce products from shop page
function theme_name_woocoomerce_exclude_products($wq){
$wq->set("post__not_in", array(21,25)); //products ID, those products will be hide from shop page
}
add_filter("woocommerce_product_query", "theme_name_woocoomerce_exclude_products");
//exclude products by category name
function theme_name_exclude_category_products($wq){
$tax_query = (array)$wq->get('tax_query');
$tax_query[] =array(
'taxonomy' => 'product_cat';
'field' => 'slug',
'terms' => array('category_name'),
'operator' => 'NOT IN'
);
$wq->set('tax_query', $tax_query);
return $wq;
}
add_filter('woocommerce_product_query', 'theme_name_exclude_category_products);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment