Created
August 24, 2018 12:45
-
-
Save kartikparmar/0681fbe3caa7d2b6239f2440700d62a5 to your computer and use it in GitHub Desktop.
Get all WooCommerce product ids
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
<?php | |
/** | |
* Function to fetch all WooCommerce product ids. | |
*/ | |
function get_all_wc_products_ids() { | |
$args = array( | |
'post_type' => array( 'product' ), | |
'posts_per_page' => -1, | |
'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ), // 'all' | |
); | |
$product = get_posts( $args ); | |
$all_products = array(); | |
foreach ( $product as $k => $value ) { | |
$all_products[] = $value->ID; | |
} | |
return $all_products; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment