Created
November 22, 2023 05:49
-
-
Save devendrabisht/5da458e6a13bd4fc9ada08954620cbc9 to your computer and use it in GitHub Desktop.
Forcefully show draft products on frontend - WooCommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function devxwp_show_draft_products_on_frontend( $query ) { | |
// echo '<pre>'; | |
// print_r($query); | |
// echo '</pre>'; | |
if( ! current_user_can( 'administrator' ) ) { return; } | |
if ( ! is_admin() && $query->is_main_query() ) { | |
// Not a query for an admin page. | |
// It's the main query for a front end page of your site. | |
if ( is_product_category() ) { | |
// It's the main query for a category archive. | |
// Let's change the query for category archives. | |
$query->set( 'post_status', array( 'publish', 'draft' ) ); | |
} | |
} | |
} | |
add_action( 'pre_get_posts', 'devxwp_show_draft_products_on_frontend', 20, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment