wpdb = $wpdb; } public function getCustomFieldCount($field, $postTypes) { $response = $this->wpdb->get_row( $this->wpdb->prepare( " SELECT COUNT(DISTINCT p.`ID`) as 'count' FROM `{$this->wpdb->prefix}postmeta` AS pm, `{$this->wpdb->prefix}posts` AS p WHERE pm.`meta_key` = BINARY %s AND pm.`post_id` = p.`ID` AND p.`post_type` IN($postTypes) ", array($field) ) ); return $response->count; } public function getAttributes() { $wcAttributesInfo = array('wc_taxonomies' => array()); if (is_plugin_active('woocommerce/woocommerce.php')) { $wcAttributesInfo['wc_taxonomies'] = wc_get_attribute_taxonomies(); } return $wcAttributesInfo; } public function getLocalAttributes($type, $ids) { $localAttrs = array(); if ($type === "import-products") { foreach ($ids as $id) { $order = wc_get_order($id); if (!empty($order)) { foreach ($order->get_items() as $itemData) { $productId = $itemData->get_product()->get_ID(); $this->getFormatLocalAttributes($productId, $localAttrs); } } } } else { foreach ($ids as $id) { $this->getFormatLocalAttributes($id, $localAttrs); } } $tempArr = array_unique(array_column($localAttrs, 'name')); $result = array_intersect_key($localAttrs, $tempArr); return array('local_attributes' => $result); } private function getFormatLocalAttributes($id, &$localAttrs) { $product = get_post($id); $parentProductId = 'product_variation' === $product->post_type ? $product->post_parent : $id; $attributes = get_post_meta($parentProductId, '_product_attributes', true); if ($attributes) { foreach ($attributes as $key => $value) { if (!preg_match("/^pa_/", $key)) { $localAttrs[] = array("name" => $value["name"]); } } } } }