/** * Gte woocommerce data for product * * @param $value * @param $data * * @return string */ function vc_gitem_template_attribute_woocommerce_product($value, $data) { $label = ''; /** * @var null|Wp_Post $post ; * @var string $data ; */ extract(array_merge(array('post' => null, 'data' => ''), $data)); require_once WC()->plugin_path() . '/includes/abstracts/abstract-wc-product.php'; $product = new WC_Product($post); if (preg_match('/_labeled$/', $data)) { $data = preg_replace('/_labeled$/', '', $data); $label = apply_filters('vc_gitem_template_attribute_woocommerce_product_' . $data . '_label', Vc_Vendor_Woocommerce::getProductFieldLabel($data) . ': '); } $price_format = get_woocommerce_price_format(); switch ($data) { case 'id': $value = (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id; break; case 'sku': $value = $product->get_sku(); break; case 'price': $value = sprintf($price_format, wc_format_decimal($product->get_price(), 2), get_woocommerce_currency()); break; case 'regular_price': $value = sprintf($price_format, wc_format_decimal($product->get_regular_price(), 2), get_woocommerce_currency()); break; case 'sale_price': $value = sprintf(get_woocommerce_price_format(), $product->get_sale_price() ? wc_format_decimal($product->get_sale_price(), 2) : '', get_woocommerce_currency()); break; case 'price_html': $value = $product->get_price_html(); break; case 'reviews_count': $value = count(get_comments(array('post_id' => $post->ID, 'approve' => 'approve'))); break; case 'short_description': $value = apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt); break; case 'dimensions': $units = get_option('woocommerce_dimension_unit'); $value = $product->length . $units . 'x' . $product->width . $units . 'x' . $product->height . $units; break; case 'raiting_count': $value = $product->get_rating_count(); break; case 'weight': $value = $product->get_weight() ? wc_format_decimal($product->get_weight(), 2) : ''; break; case 'on_sale': $value = $product->is_on_sale() ? 'yes' : 'no'; // @todo change break; default: $value = $product->{$data}; } return strlen($value) > 0 ? $label . apply_filters('vc_gitem_template_attribute_woocommerce_product_' . $data . '_value', $value) : ''; }
/** * Listens to see if an item is added to the cart. If it is, * this will check to see if the item is a ipad enclosure. * If the item is an ipad enclosure it will then add a filter * telling the customer to pick up an ipad enclosure * * @param id Product ID used to instantiate a product */ function jm_add_to_cart_listener($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data) { // Fetch a product object using the product id $product = new WC_Product($product_id); // Get all of the product categories this item belongs too $terms = wp_get_post_terms($product->get_post_data()->ID, 'product_cat'); // Add all the categories to an array foreach ($terms as $term) { $categories[] = $term->slug; } // If the array contains ipad-enclosures we know this was indeed a mount if (in_array('ipad-enclosures', $categories)) { add_filter('woocommerce_add_to_cart_message', 'jm_add_to_cart_ipad_enclosure', 999); } // If the array contains ipad-enclosures we know this was indeed a enclosure if (in_array('ipad-mounts', $categories)) { add_filter('woocommerce_add_to_cart_message', 'jm_add_to_cart_ipad_mount', 999); } }
/** * Get standard product data that applies to every product type * * @since 2.1 * @param WC_Product $product * @return WC_Product */ private function get_product_data($product) { return array('title' => $product->get_title(), 'id' => (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id, 'created_at' => $this->server->format_datetime($product->get_post_data()->post_date_gmt), 'updated_at' => $this->server->format_datetime($product->get_post_data()->post_modified_gmt), 'type' => $product->product_type, 'status' => $product->get_post_data()->post_status, 'downloadable' => $product->is_downloadable(), 'virtual' => $product->is_virtual(), 'permalink' => $product->get_permalink(), 'sku' => $product->get_sku(), 'price' => $product->get_price(), 'regular_price' => $product->get_regular_price(), 'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : null, 'price_html' => $product->get_price_html(), 'taxable' => $product->is_taxable(), 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'managing_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'purchaseable' => $product->is_purchasable(), 'featured' => $product->is_featured(), 'visible' => $product->is_visible(), 'catalog_visibility' => $product->visibility, 'on_sale' => $product->is_on_sale(), 'product_url' => $product->is_type('external') ? $product->get_product_url() : '', 'button_text' => $product->is_type('external') ? $product->get_button_text() : '', 'weight' => $product->get_weight() ? $product->get_weight() : null, 'dimensions' => array('length' => $product->length, 'width' => $product->width, 'height' => $product->height, 'unit' => get_option('woocommerce_dimension_unit')), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => 0 !== $product->get_shipping_class_id() ? $product->get_shipping_class_id() : null, 'description' => wpautop(do_shortcode($product->get_post_data()->post_content)), 'short_description' => apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt), 'reviews_allowed' => 'open' === $product->get_post_data()->comment_status, 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => (int) $product->get_rating_count(), 'related_ids' => array_map('absint', array_values($product->get_related())), 'upsell_ids' => array_map('absint', $product->get_upsells()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sells()), 'parent_id' => $product->post->post_parent, 'categories' => wp_get_post_terms($product->id, 'product_cat', array('fields' => 'names')), 'tags' => wp_get_post_terms($product->id, 'product_tag', array('fields' => 'names')), 'images' => $this->get_images($product), 'featured_src' => (string) wp_get_attachment_url(get_post_thumbnail_id($product->is_type('variation') ? $product->variation_id : $product->id)), 'attributes' => $this->get_attributes($product), 'downloads' => $this->get_downloads($product), 'download_limit' => (int) $product->download_limit, 'download_expiry' => (int) $product->download_expiry, 'download_type' => $product->download_type, 'purchase_note' => wpautop(do_shortcode(wp_kses_post($product->purchase_note))), 'total_sales' => metadata_exists('post', $product->id, 'total_sales') ? (int) get_post_meta($product->id, 'total_sales', true) : 0, 'variations' => array(), 'parent' => array(), 'grouped_products' => array()); }
/** * Gets an individual ticket * * @param $event_id * @param $ticket_id * * @return null|Tribe__Tickets__Ticket_Object */ public function get_ticket($event_id, $ticket_id) { if (class_exists('WC_Product_Simple')) { $product = new WC_Product_Simple($ticket_id); } else { $product = new WC_Product($ticket_id); } if (!$product) { return null; } $return = new Tribe__Tickets__Ticket_Object(); $product_data = $product->get_post_data(); $qty = get_post_meta($ticket_id, 'total_sales', true); $return->description = $product_data->post_excerpt; $return->frontend_link = get_permalink($ticket_id); $return->ID = $ticket_id; $return->name = $product->get_title(); $return->price = $product->get_price(); $return->regular_price = $product->get_regular_price(); $return->on_sale = (bool) $product->is_on_sale(); $return->provider_class = get_class($this); $return->admin_link = admin_url(sprintf(get_post_type_object($product_data->post_type)->_edit_link . '&action=edit', $ticket_id)); $return->start_date = get_post_meta($ticket_id, '_ticket_start_date', true); $return->end_date = get_post_meta($ticket_id, '_ticket_end_date', true); $return->purchase_limit = get_post_meta($ticket_id, '_ticket_purchase_limit', true); $complete_totals = $this->count_order_items_by_status($ticket_id, 'complete'); $pending_totals = $this->count_order_items_by_status($ticket_id, 'incomplete'); $qty = $qty ? $qty : 0; $pending = $pending_totals['total'] ? $pending_totals['total'] : 0; // if any orders transitioned from complete back to one of the incomplete states, their quantities // were already recorded in total_sales and we have to deduct them from there so they aren't // double counted $qty -= $pending_totals['recorded_sales']; // let's calculate the stock based on the product stock minus the quantity purchased minus the // pending purchases $stock = $product->get_stock_quantity() - $qty - $pending; // if any orders have reduced the stock of an order (check and cash on delivery payments do this, for example) // we need to re-inflate the stock by that amount $stock += $pending_totals['reduced_stock']; $stock += $complete_totals['reduced_stock']; $return->manage_stock($product->managing_stock()); $return->stock($stock); $return->qty_sold($qty); $return->qty_pending($pending); $return->qty_cancelled($this->get_cancelled($ticket_id)); if (empty($return->purchase_limit) && 0 !== (int) $return->purchase_limit) { /** * Filter the default purchase limit for the ticket * * @var int * * @return int */ $return->purchase_limit = apply_filters('tribe_tickets_default_purchase_limit', 0); } return apply_filters('wootickets_get_ticket', $return, $event_id, $ticket_id); }
/** * Gets an individual ticket * * @param $event_id * @param $ticket_id * * @return null|Tribe__Events__Tickets__Ticket_Object */ public function get_ticket($event_id, $ticket_id) { if (class_exists('WC_Product_Simple')) { $product = new WC_Product_Simple($ticket_id); } else { $product = new WC_Product($ticket_id); } if (!$product) { return null; } $return = new Tribe__Events__Tickets__Ticket_Object(); $product_data = $product->get_post_data(); $qty = get_post_meta($ticket_id, 'total_sales', true); $return->description = $product_data->post_excerpt; $return->frontend_link = get_permalink($ticket_id); $return->ID = $ticket_id; $return->name = $product->get_title(); $return->price = $product->get_price(); $return->regular_price = $product->get_regular_price(); $return->on_sale = (bool) $product->is_on_sale(); $return->provider_class = get_class($this); $return->admin_link = admin_url(sprintf(get_post_type_object($product_data->post_type)->_edit_link . '&action=edit', $ticket_id)); $return->stock = $product->get_stock_quantity(); $return->start_date = get_post_meta($ticket_id, '_ticket_start_date', true); $return->end_date = get_post_meta($ticket_id, '_ticket_end_date', true); $return->qty_sold = $qty ? $qty : 0; $return->qty_pending = $qty ? $this->count_incomplete_order_items($ticket_id) : 0; $return->purchase_limit = get_post_meta($ticket_id, '_ticket_purchase_limit', true); if (empty($return->purchase_limit) && 0 !== (int) $return->purchase_limit) { /** * Filter the default purchase limit for the ticket * * @var int * * @return int */ $return->purchase_limit = apply_filters('tribe_tickets_default_purchase_limit', 0); } return apply_filters('wootickets_get_ticket', $return, $event_id, $ticket_id); }
/** * Get product data. * * @param WC_Product $product * @return array */ protected function get_product_data($product) { $data = array('id' => (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id, 'name' => $product->get_title(), 'slug' => $product->get_post_data()->post_name, 'permalink' => $product->get_permalink(), 'date_created' => wc_rest_prepare_date_response($product->get_post_data()->post_date_gmt), 'date_modified' => wc_rest_prepare_date_response($product->get_post_data()->post_modified_gmt), 'type' => $product->product_type, 'status' => $product->get_post_data()->post_status, 'featured' => $product->is_featured(), 'catalog_visibility' => $product->visibility, 'description' => wpautop(do_shortcode($product->get_post_data()->post_content)), 'short_description' => apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt), 'sku' => $product->get_sku(), 'price' => $product->get_price(), 'regular_price' => $product->get_regular_price(), 'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : '', 'date_on_sale_from' => $product->sale_price_dates_from ? date('Y-m-d', $product->sale_price_dates_from) : '', 'date_on_sale_to' => $product->sale_price_dates_to ? date('Y-m-d', $product->sale_price_dates_to) : '', 'price_html' => $product->get_price_html(), 'on_sale' => $product->is_on_sale(), 'purchasable' => $product->is_purchasable(), 'total_sales' => (int) get_post_meta($product->id, 'total_sales', true), 'virtual' => $product->is_virtual(), 'downloadable' => $product->is_downloadable(), 'downloads' => $this->get_downloads($product), 'download_limit' => '' !== $product->download_limit ? (int) $product->download_limit : -1, 'download_expiry' => '' !== $product->download_expiry ? (int) $product->download_expiry : -1, 'download_type' => $product->download_type ? $product->download_type : 'standard', 'external_url' => $product->is_type('external') ? $product->get_product_url() : '', 'button_text' => $product->is_type('external') ? $product->get_button_text() : '', 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'manage_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders' => $product->backorders, 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'weight' => $product->get_weight(), 'dimensions' => array('length' => $product->get_length(), 'width' => $product->get_width(), 'height' => $product->get_height()), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => (int) $product->get_shipping_class_id(), 'reviews_allowed' => 'open' === $product->get_post_data()->comment_status, 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => (int) $product->get_rating_count(), 'related_ids' => array_map('absint', array_values($product->get_related())), 'upsell_ids' => array_map('absint', $product->get_upsells()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sells()), 'parent_id' => $product->is_type('variation') ? $product->parent->id : $product->get_post_data()->post_parent, 'purchase_note' => wpautop(do_shortcode(wp_kses_post($product->purchase_note))), 'categories' => $this->get_taxonomy_terms($product), 'tags' => $this->get_taxonomy_terms($product, 'tag'), 'images' => $this->get_images($product), 'attributes' => $this->get_attributes($product), 'default_attributes' => $this->get_default_attributes($product), 'variations' => array(), 'grouped_products' => array(), 'menu_order' => $this->get_product_menu_order($product)); return $data; }
private function get_product_from_post($post_id) { $woocommerce_ver_below_2_1 = false; if (version_compare(WOOCOMMERCE_VERSION, '2.1', '<')) { $woocommerce_ver_below_2_1 = true; } if ($woocommerce_ver_below_2_1) { $product = new WC_Product_Simple($post_id); } else { $product = new WC_Product($post_id); } //$post_categories = wp_get_post_categories( $post_id ); //$categories = get_the_category(); try { $thumbnail = $product->get_image(); if ($thumbnail) { if (preg_match('/data-lazy-src="([^\\"]+)"/s', $thumbnail, $match)) { $thumbnail = $match[1]; } else { if (preg_match('/data-lazy-original="([^\\"]+)"/s', $thumbnail, $match)) { $thumbnail = $match[1]; } else { if (preg_match('/lazy-src="([^\\"]+)"/s', $thumbnail, $match)) { // Animate Lazy Load Wordpress Plugin $thumbnail = $match[1]; } else { if (preg_match('/data-echo="([^\\"]+)"/s', $thumbnail, $match)) { $thumbnail = $match[1]; } else { preg_match('/<img(.*)src(.*)=(.*)"(.*)"/U', $thumbnail, $result); $thumbnail = array_pop($result); } } } } } } catch (Exception $e) { $err_msg = "exception raised in thumbnails"; self::send_error_report($err_msg); $thumbnail = ''; } // handling scheduled sale price update if (!$woocommerce_ver_below_2_1) { $sale_price_dates_from = get_post_meta($post_id, '_sale_price_dates_from', true); $sale_price_dates_to = get_post_meta($post_id, '_sale_price_dates_to', true); if ($sale_price_dates_from || $sale_price_dates_to) { self::schedule_sale_price_update($post_id, null); } if ($sale_price_dates_from) { self::schedule_sale_price_update($post_id, $sale_price_dates_from); } if ($sale_price_dates_to) { self::schedule_sale_price_update($post_id, $sale_price_dates_to); } } $product_tags = array(); foreach (wp_get_post_terms($post_id, 'product_tag') as $tag) { $product_tags[] = $tag->name; } $product_brands = array(); if (taxonomy_exists('product_brand')) { foreach (wp_get_post_terms($post_id, 'product_brand') as $brand) { $product_brands[] = $brand->name; } } $taxonomies = array(); try { $all_taxonomies = get_option('wcis_taxonomies'); if (is_array($all_taxonomies)) { foreach ($all_taxonomies as $taxonomy) { if (taxonomy_exists($taxonomy) && !array_key_exists($taxonomy, $taxonomies)) { foreach (wp_get_post_terms($post_id, $taxonomy) as $taxonomy_value) { if (!array_key_exists($taxonomy, $taxonomies)) { $taxonomies[$taxonomy] = array(); } $taxonomies[$taxonomy][] = $taxonomy_value->name; } } } } } catch (Exception $e) { } $acf_fields = array(); try { if (class_exists('acf') && function_exists('get_field')) { $all_acf_fields = get_option('wcis_acf_fields'); if (is_array($all_acf_fields)) { foreach ($all_acf_fields as $acf_field_name) { $acf_field_value = get_field($acf_field_name, $post_id); if ($acf_field_value) { $acf_fields[$acf_field_name] = $acf_field_value; } } } } } catch (Exception $e) { } $send_product = array('product_id' => $product->id, 'currency' => get_woocommerce_currency(), 'price' => $product->get_price(), 'url' => get_permalink($product->id), 'thumbnail_url' => $thumbnail, 'action' => 'insert', 'description' => $product->get_post_data()->post_content, 'short_description' => $product->get_post_data()->post_excerpt, 'name' => $product->get_title(), 'sku' => $product->get_sku(), 'categories' => $product->get_categories(), 'tag' => $product_tags, 'store_id' => get_current_blog_id(), 'identifier' => (string) $product->id, 'product_brand' => $product_brands, 'taxonomies' => $taxonomies, 'acf_fields' => $acf_fields, 'sellable' => $product->is_purchasable(), 'visibility' => $product->is_visible(), 'stock_quantity' => $product->get_stock_quantity(), 'is_managing_stock' => $product->managing_stock(), 'is_backorders_allowed' => $product->backorders_allowed(), 'is_purchasable' => $product->is_purchasable(), 'is_in_stock' => $product->is_in_stock(), 'product_status' => get_post_status($post_id)); try { $variable = new WC_Product_Variable($post_id); $variations = $variable->get_available_variations(); $variations_sku = ''; if (!empty($variations)) { foreach ($variations as $variation) { if ($product->get_sku() != $variation['sku']) { $variations_sku .= $variation['sku'] . ' '; } } } $send_product['variations_sku'] = $variations_sku; $all_attributes = $product->get_attributes(); $attributes = array(); if (!empty($all_attributes)) { foreach ($all_attributes as $attr_mame => $value) { if ($all_attributes[$attr_mame]['is_taxonomy']) { if (!$woocommerce_ver_below_2_1) { $attributes[$attr_mame] = wc_get_product_terms($post_id, $attr_mame, array('fields' => 'names')); } else { $attributes[$attr_mame] = woocommerce_get_product_terms($post_id, $attr_mame, 'names'); } } else { $attributes[$attr_mame] = $product->get_attribute($attr_mame); } } } $send_product['attributes'] = $attributes; $send_product['total_variable_stock'] = $variable->get_total_stock(); try { if (version_compare(WOOCOMMERCE_VERSION, '2.2', '>=')) { if (function_exists('wc_get_product')) { $original_product = wc_get_product($product->id); if (is_object($original_product)) { $send_product['visibility'] = $original_product->is_visible(); $send_product['product_type'] = $original_product->product_type; } } } else { if (function_exists('get_product')) { $original_product = get_product($product->id); if (is_object($original_product)) { $send_product['visibility'] = $original_product->is_visible(); $send_product['product_type'] = $original_product->product_type; } } } } catch (Exception $e) { } } catch (Exception $e) { $err_msg = "exception raised in attributes"; self::send_error_report($err_msg); } if (!$woocommerce_ver_below_2_1) { try { $send_product['price_compare_at_price'] = $product->get_regular_price(); $send_product['price_min'] = $variable->get_variation_price('min'); $send_product['price_max'] = $variable->get_variation_price('max'); $send_product['price_min_compare_at_price'] = $variable->get_variation_regular_price('min'); $send_product['price_max_compare_at_price'] = $variable->get_variation_regular_price('max'); } catch (Exception $e) { $send_product['price_compare_at_price'] = null; $send_product['price_min'] = null; $send_product['price_max'] = null; $send_product['price_min_compare_at_price'] = null; $send_product['price_max_compare_at_price'] = null; } } else { $send_product['price_compare_at_price'] = null; $send_product['price_min'] = null; $send_product['price_max'] = null; $send_product['price_min_compare_at_price'] = null; $send_product['price_max_compare_at_price'] = null; } $send_product['description'] = self::content_filter_shortcode_with_content($send_product['description']); $send_product['short_description'] = self::content_filter_shortcode_with_content($send_product['short_description']); $send_product['description'] = self::content_filter_shortcode($send_product['description']); $send_product['short_description'] = self::content_filter_shortcode($send_product['short_description']); try { if (defined('ICL_SITEPRESS_VERSION') && is_plugin_active('woocommerce-multilingual/wpml-woocommerce.php') && function_exists('wpml_get_language_information')) { if (version_compare(ICL_SITEPRESS_VERSION, '3.2', '>=')) { $language_info = apply_filters('wpml_post_language_details', NULL, $post_id); } else { $language_info = wpml_get_language_information($post_id); } if ($language_info && is_array($language_info) && array_key_exists('locale', $language_info)) { // WP_Error could be returned from wpml_get_language_information(...) $send_product['lang'] = $language_info['locale']; } } } catch (Exception $e) { } return $send_product; }
/** * Gets an individual ticket * * @param $unused_event_id * @param $ticket_id * * @return null|Tribe__Events__Tickets__Ticket_Object */ public function get_ticket($unused_event_id, $ticket_id) { if (class_exists('WC_Product_Simple')) { $product = new WC_Product_Simple($ticket_id); } else { $product = new WC_Product($ticket_id); } if (!$product) { return null; } $return = new Tribe__Events__Tickets__Ticket_Object(); $product_data = $product->get_post_data(); $qty = get_post_meta($ticket_id, 'total_sales', true); $return->description = $product_data->post_excerpt; $return->frontend_link = get_permalink($ticket_id); $return->ID = $ticket_id; $return->name = $product->get_title(); $return->price = $product->get_price(); $return->regular_price = $product->get_regular_price(); $return->on_sale = (bool) $product->is_on_sale(); $return->provider_class = get_class($this); $return->admin_link = admin_url(sprintf(get_post_type_object($product_data->post_type)->_edit_link . '&action=edit', $ticket_id)); $return->stock = $product->get_stock_quantity(); $return->start_date = get_post_meta($ticket_id, '_ticket_start_date', true); $return->end_date = get_post_meta($ticket_id, '_ticket_end_date', true); $return->qty_sold = $qty ? $qty : 0; $return->qty_pending = $qty ? $this->count_incomplete_order_items($ticket_id) : 0; return $return; }
/** * @param WP_Post $product * * @return array */ public static function getArticleCampaign($product) { $productId = $product->ID; $product = new WC_Product($productId); $serialized = array('id' => $productId, 'name' => $product->get_title(), 'url' => $product->get_permalink()); $description = $product->get_post_data()->post_content; if (!empty($description)) { $serialized['description'] = $description; } $imageUrl = wp_get_attachment_url(get_post_thumbnail_id($productId)); if (!empty($imageUrl)) { $serialized['image_url'] = $imageUrl; } return $serialized; }
/** * Get standard product data that applies to every product type * * @since 2.1 * @param WC_Product $product * @return WC_Product */ private function get_product_data($product, $fields = null) { if ($fields) { $field_list = explode(',', $fields); } $product_data = array(); if (!$fields || $fields && in_array('title', $field_list)) { $product_data['title'] = $product->get_title(); } if (!$fields || $fields && in_array('id', $field_list)) { $product_data['id'] = (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id; } if (!$fields || $fields && in_array('created_at', $field_list)) { $product_data['created_at'] = $this->server->format_datetime($product->get_post_data()->post_date_gmt); } if (!$fields || $fields && in_array('updated_at', $field_list)) { $product_data['updated_at'] = $this->server->format_datetime($product->get_post_data()->post_modified_gmt); } if (!$fields || $fields && in_array('type', $field_list)) { $product_data['type'] = $product->product_type; } if (!$fields || $fields && in_array('status', $field_list)) { $product_data['status'] = $product->get_post_data()->post_status; } if (!$fields || $fields && in_array('downloadable', $field_list)) { $product_data['downloadable'] = $product->is_downloadable(); } if (!$fields || $fields && in_array('virtual', $field_list)) { $product_data['virtual'] = $product->is_virtual(); } if (!$fields || $fields && in_array('permalink', $field_list)) { $product_data['permalink'] = $product->get_permalink(); } if (!$fields || $fields && in_array('sku', $field_list)) { $product_data['sku'] = $product->get_sku(); } if (!$fields || $fields && in_array('price', $field_list)) { $product_data['price'] = $product->get_price(); } if (!$fields || $fields && in_array('regular_price', $field_list)) { $product_data['regular_price'] = $product->get_regular_price(); } if (!$fields || $fields && in_array('sale_price', $field_list)) { $product_data['sale_price'] = $product->get_sale_price() ? $product->get_sale_price() : null; } if (!$fields || $fields && in_array('price_html', $field_list)) { $product_data['price_html'] = $product->get_price_html(); } if (!$fields || $fields && in_array('taxable', $field_list)) { $product_data['taxable'] = $product->is_taxable(); } if (!$fields || $fields && in_array('tax_status', $field_list)) { $product_data['tax_status'] = $product->get_tax_status(); } if (!$fields || $fields && in_array('tax_class', $field_list)) { $product_data['tax_class'] = $product->get_tax_class(); } if (!$fields || $fields && in_array('managing_stock', $field_list)) { $product_data['managing_stock'] = $product->managing_stock(); } if (!$fields || $fields && in_array('stock_quantity', $field_list)) { $product_data['stock_quantity'] = $product->get_stock_quantity(); } if (!$fields || $fields && in_array('in_stock', $field_list)) { $product_data['in_stock'] = $product->is_in_stock(); } if (!$fields || $fields && in_array('backorders_allowed', $field_list)) { $product_data['backorders_allowed'] = $product->backorders_allowed(); } if (!$fields || $fields && in_array('backordered', $field_list)) { $product_data['backordered'] = $product->is_on_backorder(); } if (!$fields || $fields && in_array('sold_individually', $field_list)) { $product_data['sold_individually'] = $product->is_sold_individually(); } if (!$fields || $fields && in_array('purchaseable', $field_list)) { $product_data['purchaseable'] = $product->is_purchasable(); } if (!$fields || $fields && in_array('featured', $field_list)) { $product_data['featured'] = $product->is_featured(); } if (!$fields || $fields && in_array('visible', $field_list)) { $product_data['visible'] = $product->is_visible(); } if (!$fields || $fields && in_array('catalog_visibility', $field_list)) { $product_data['catalog_visibility'] = $product->visibility; } if (!$fields || $fields && in_array('on_sale', $field_list)) { $product_data['on_sale'] = $product->is_on_sale(); } if (!$fields || $fields && in_array('product_url', $field_list)) { $product_data['product_url'] = $product->is_type('external') ? $product->get_product_url() : ''; } if (!$fields || $fields && in_array('button_text', $field_list)) { $product_data['button_text'] = $product->is_type('external') ? $product->get_button_text() : ''; } if (!$fields || $fields && in_array('weight', $field_list)) { $product_data['weight'] = $product->get_weight() ? $product->get_weight() : null; } if (!$fields || $fields && in_array('dimensions', $field_list)) { $product_data['dimensions'] = array('length' => $product->length, 'width' => $product->width, 'height' => $product->height, 'unit' => get_option('woocommerce_dimension_unit')); } if (!$fields || $fields && in_array('shipping_required', $field_list)) { $product_data['shipping_required'] = $product->needs_shipping(); } if (!$fields || $fields && in_array('shipping_taxable', $field_list)) { $product_data['shipping_taxable'] = $product->is_shipping_taxable(); } if (!$fields || $fields && in_array('shipping_class', $field_list)) { $product_data['shipping_class'] = $product->get_shipping_class(); } if (!$fields || $fields && in_array('shipping_class_id', $field_list)) { $product_data['shipping_class_id'] = 0 !== $product->get_shipping_class_id() ? $product->get_shipping_class_id() : null; } if (!$fields || $fields && in_array('description', $field_list)) { $product_data['description'] = wpautop(do_shortcode($product->get_post_data()->post_content)); } if (!$fields || $fields && in_array('short_description', $field_list)) { $product_data['short_description'] = apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt); } if (!$fields || $fields && in_array('reviews_allowed', $field_list)) { $product_data['reviews_allowed'] = 'open' === $product->get_post_data()->comment_status; } if (!$fields || $fields && in_array('average_rating', $field_list)) { $product_data['average_rating'] = wc_format_decimal($product->get_average_rating(), 2); } if (!$fields || $fields && in_array('rating_count', $field_list)) { $product_data['rating_count'] = (int) $product->get_rating_count(); } if (!$fields || $fields && in_array('related_ids', $field_list)) { $product_data['related_ids'] = array_map('absint', array_values($product->get_related())); } if (!$fields || $fields && in_array('upsell_ids', $field_list)) { $product_data['upsell_ids'] = array_map('absint', $product->get_upsells()); } if (!$fields || $fields && in_array('cross_sell_ids', $field_list)) { $product_data['cross_sell_ids'] = array_map('absint', $product->get_cross_sells()); } if (!$fields || $fields && in_array('parent_id', $field_list)) { $product_data['parent_id'] = $product->post->post_parent; } if (!$fields || $fields && in_array('categories', $field_list)) { $product_data['categories'] = wp_get_post_terms($product->id, 'product_cat', array('fields' => 'names')); } if (!$fields || $fields && in_array('tags', $field_list)) { $product_data['tags'] = wp_get_post_terms($product->id, 'product_tag', array('fields' => 'names')); } if (!$fields || $fields && in_array('images', $field_list)) { $product_data['images'] = $this->get_images($product); } if (!$fields || $fields && in_array('featured_src', $field_list)) { $product_data['featured_src'] = (string) wp_get_attachment_url(get_post_thumbnail_id($product->is_type('variation') ? $product->variation_id : $product->id)); } if (!$fields || $fields && in_array('attributes', $field_list)) { $product_data['attributes'] = $this->get_attributes($product); } if (!$fields || $fields && in_array('downloads', $field_list)) { $product_data['downloads'] = $this->get_downloads($product); } if (!$fields || $fields && in_array('download_limit', $field_list)) { $product_data['download_limit'] = (int) $product->download_limit; } if (!$fields || $fields && in_array('download_expiry', $field_list)) { $product_data['download_expiry'] = (int) $product->download_expiry; } if (!$fields || $fields && in_array('download_type', $field_list)) { $product_data['download_type'] = $product->download_type; } if (!$fields || $fields && in_array('purchase_note', $field_list)) { $product_data['purchase_note'] = wpautop(do_shortcode(wp_kses_post($product->purchase_note))); } if (!$fields || $fields && in_array('total_sales', $field_list)) { $product_data['total_sales'] = metadata_exists('post', $product->id, 'total_sales') ? (int) get_post_meta($product->id, 'total_sales', true) : 0; } if (!$fields || $fields && in_array('variations', $field_list)) { $product_data['variations'] = array(); } if (!$fields || $fields && in_array('parent', $field_list)) { $product_data['parent'] = array(); } if (!$fields || $fields && in_array('grouped_products', $field_list)) { $product_data['grouped_products'] = array(); } if (!$fields || $fields && in_array('menu_order', $field_list)) { $product_data['menu_order'] = $product->post->menu_order; } return $product_data; }
/** * Gets an individual ticket * * @param $event_id * @param $ticket_id * * @return null|Tribe__Tickets__Ticket_Object */ public function get_ticket($event_id, $ticket_id) { if (class_exists('WC_Product_Simple')) { $product = new WC_Product_Simple($ticket_id); } else { $product = new WC_Product($ticket_id); } if (!$product) { return null; } $return = new Tribe__Tickets__Ticket_Object(); $product_data = $product->get_post_data(); $qty = get_post_meta($ticket_id, 'total_sales', true); $return->description = $product_data->post_excerpt; $return->frontend_link = get_permalink($ticket_id); $return->ID = $ticket_id; $return->name = $product->get_title(); $return->price = $product->get_price(); $return->regular_price = $product->get_regular_price(); $return->on_sale = (bool) $product->is_on_sale(); $return->provider_class = get_class($this); $return->admin_link = admin_url(sprintf(get_post_type_object($product_data->post_type)->_edit_link . '&action=edit', $ticket_id)); $return->start_date = get_post_meta($ticket_id, '_ticket_start_date', true); $return->end_date = get_post_meta($ticket_id, '_ticket_end_date', true); $return->purchase_limit = get_post_meta($ticket_id, '_ticket_purchase_limit', true); $complete_totals = $this->count_order_items_by_status($ticket_id, 'complete'); $pending_totals = $this->count_order_items_by_status($ticket_id, 'incomplete'); $qty = $qty ? $qty : 0; $pending = $pending_totals['total'] ? $pending_totals['total'] : 0; // Ticket stock is a simple reflection of remaining inventory for this item... $stock = $product->get_stock_quantity(); // ...With some exceptions for global stock tickets $stock = $this->set_stock_level_for_global_stock_tickets($stock, $event_id, $ticket_id); $return->manage_stock($product->managing_stock()); $return->stock($stock); $return->global_stock_mode(get_post_meta($ticket_id, '_global_stock_mode', true)); $return->global_stock_cap(get_post_meta($ticket_id, '_global_stock_cap', true)); $return->qty_sold($qty); $return->qty_pending($pending); $return->qty_cancelled($this->get_cancelled($ticket_id)); if (empty($return->purchase_limit) && 0 !== (int) $return->purchase_limit) { /** * Filter the default purchase limit for the ticket * * @var int * * @return int */ $return->purchase_limit = apply_filters('tribe_tickets_default_purchase_limit', 0); } return apply_filters('wootickets_get_ticket', $return, $event_id, $ticket_id); }
'post_type' => array( 'product', 'product_variation' ), 'posts_per_page' => -1, 'post_status' => 'publish', 'orderby' => esc_attr( $orderby ), 'order' => 'asc', 'post__in' => $product_ids, 'meta_key' => $meta_key, 'fields' => 'id=>parent', ));*/ foreach ($product_ids as $post_id) { if (function_exists('get_product')) { $product = get_product($post_id); } else { $product = new WC_Product($post_id); } $product_post = $product->get_post_data(); show_stock_report_row($product_post, $product); foreach ($variation_ids as $var_id => $parent) { if ($parent == $product_post->ID) { if (function_exists('get_product')) { $variation = get_product($var_id); $variation_post = $product->get_post_data(); } else { $variation = new WC_Product_Variation($var_id); $variation_post = get_post($var_id); } unset($variation_ids[$var_id]); show_stock_report_row($variation_post, $variation, true); } } }