Skip to content

Instantly share code, notes, and snippets.

@shameemreza
Created April 28, 2025 02:00
Show Gist options
  • Save shameemreza/ef6b17dfc1fb1886465e6312b8744268 to your computer and use it in GitHub Desktop.
Save shameemreza/ef6b17dfc1fb1886465e6312b8744268 to your computer and use it in GitHub Desktop.
Adds a "No Vendor" filter link to the WooCommerce Products admin screen for stores using WooCommerce Product Vendors.
// Add custom view for products without a vendor
add_filter( 'views_edit-product', function( $views ) {
$class = ( isset($_GET['no_vendor']) && $_GET['no_vendor'] == 1 ) ? 'current' : '';
$url = add_query_arg( 'no_vendor', '1', admin_url( 'edit.php?post_type=product' ) );
$views['no_vendor'] = "<a href='{$url}' class='{$class}'>No Vendor</a>";
return $views;
});
// Modify the query to show products without vendor when selected
add_action( 'pre_get_posts', function( $query ) {
if ( !is_admin() || !$query->is_main_query() ) {
return;
}
if ( isset( $_GET['no_vendor'] ) && $_GET['no_vendor'] == 1 ) {
$query->set( 'tax_query', array(
array(
'taxonomy' => 'wcpv_product_vendors',
'operator' => 'NOT EXISTS'
)
));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment