mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-02 12:02:25 +08:00
https://stackoverflow.com/questions/77725036/hide-woocommerce-products-with-a-pending-status-from-homepage
14 lines
608 B
Text
14 lines
608 B
Text
// For products shortcode (Home page?)
|
|
add_filter( 'woocommerce_shortcode_products_query', 'shortcode_product_query_excl_pending_status', 50, 3 );
|
|
function shortcode_product_query_excl_pending_status( $query_args, $atts, $loop_name ){
|
|
$query_args['post_status'] = 'publish';
|
|
return $query_args;
|
|
}
|
|
|
|
// For WooCommerce Archive pages
|
|
add_action( 'woocommerce_product_query', 'product_query_excl_pending_status', 50, 2 );
|
|
function product_query_excl_pending_status( $q, $query ) {
|
|
if ( ! is_admin() && $q->is_main_query() && $q->is_archive() ) {
|
|
$q->set('post_status', 'publish');
|
|
}
|
|
}
|