'product_cat', 'orderby' => 'name', 'hide_empty' => false, ); $allCategories = get_categories($args); // get list of categories // sorting out all categories and preparing data for sending to the front-line foreach ($allCategories as $itemCategory) { $listCategories[] = array( 'id' => $itemCategory->term_id, 'name' => $itemCategory->name, 'countProds' => $itemCategory->category_count, 'parent' => $itemCategory->category_parent, ); } // if the data array is empty, then remember the error if (0 == count($listCategories)) { $error[] = 'No data found on request'; } $response = array( 'list' => $listCategories, 'success' => array(), 'error' => $error, ); a4bJsonResponse($response); } /** * Return the result of creating barcodes. */ public function getBarcodes() { $postsBarcodesGenerator = new WoocommercePostsA4BarcodesMaker(); $result = $postsBarcodesGenerator->make(); a4bJsonResponse($result); } /** * return count products with costom field. */ public function countProductsByCustomField() { global $wpdb; $validationOptions = array( 'field' => 'required|string', ); // Checking for the correct data from the request. If not valid return error result. ValidatorPostData::validate($validationOptions, true); $response = $wpdb->get_row( $wpdb->prepare("SELECT COUNT(DISTINCT p.`ID`) as 'count' FROM `{$wpdb->prefix}postmeta` AS pm, `{$wpdb->prefix}posts` AS p WHERE pm.`meta_key` = %s AND pm.`post_id` = p.`ID` AND p.`post_type` IN('product_variation', 'product')", array(PostData::$postData['field']) ) ); a4bJsonResponse($response); } /** * Get woocommerce attributes info. * * @return array */ public function getAttributes() { // Default value. $wcAttributesInfo = array('wc_taxonomies' => array()); // If woocommerce active get woocommerce taxonomies. if (is_plugin_active('woocommerce/woocommerce.php')) { $wcAttributesInfo['wc_taxonomies'] = wc_get_attribute_taxonomies(); } return a4bJsonResponse(array('wc_attributes' => $wcAttributesInfo)); } }