Skip to content

Instantly share code, notes, and snippets.

@kartikparmar
Created June 27, 2019 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kartikparmar/d8c73cc879a1a327ea673c6855da308d to your computer and use it in GitHub Desktop.
Save kartikparmar/d8c73cc879a1a327ea673c6855da308d to your computer and use it in GitHub Desktop.
Return all category ids of WooCommerce
<?php
function wcget_category_ids(){
$orderby = 'name';
$order = 'asc';
$hide_empty = false ;
$cat_args = array(
'orderby' => $orderby,
'order' => $order,
'hide_empty' => $hide_empty,
);
$product_categories = get_terms( 'product_cat', $cat_args );
$category_ids = array();
if( !empty($product_categories) ){
foreach ($product_categories as $key => $value) {
$category_ids[] = $value->term_id;
}
}
return $category_ids;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment