Created
June 27, 2019 11:50
-
-
Save kartikparmar/d8c73cc879a1a327ea673c6855da308d to your computer and use it in GitHub Desktop.
Return all category ids of 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
<?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