Skip to content

Instantly share code, notes, and snippets.

@kartikparmar
Created August 24, 2018 12:45
Show Gist options
  • Save kartikparmar/0681fbe3caa7d2b6239f2440700d62a5 to your computer and use it in GitHub Desktop.
Save kartikparmar/0681fbe3caa7d2b6239f2440700d62a5 to your computer and use it in GitHub Desktop.
Get all WooCommerce product ids
<?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