get_regular_price() 공개 메소드

Returns the product's regular price.
public get_regular_price ( string $context = 'view' ) : string
$context string
리턴 string price
/**
 * 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) : '';
}
 /**
  * Get standard product data that applies to every product type
  *
  * @since 2.1
  * @param WC_Product $product
  * @return array
  */
 private function get_product_data($product)
 {
     return array('title' => $product->get_name(), 'id' => $product->get_id(), 'created_at' => $this->server->format_datetime($product->get_date_created(), false, true), 'updated_at' => $this->server->format_datetime($product->get_date_modified(), false, true), 'type' => $product->get_type(), 'status' => $product->get_status(), 'downloadable' => $product->is_downloadable(), 'virtual' => $product->is_virtual(), 'permalink' => $product->get_permalink(), 'sku' => $product->get_sku(), 'price' => wc_format_decimal($product->get_price(), 2), 'regular_price' => wc_format_decimal($product->get_regular_price(), 2), 'sale_price' => $product->get_sale_price() ? wc_format_decimal($product->get_sale_price(), 2) : 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->get_catalog_visibility(), 'on_sale' => $product->is_on_sale(), 'weight' => $product->get_weight() ? wc_format_decimal($product->get_weight(), 2) : null, 'dimensions' => array('length' => $product->get_length(), 'width' => $product->get_width(), 'height' => $product->get_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' => apply_filters('the_content', $product->get_description()), 'short_description' => apply_filters('woocommerce_short_description', $product->get_short_description()), 'reviews_allowed' => $product->get_reviews_allowed(), 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => $product->get_rating_count(), 'related_ids' => array_map('absint', array_values(wc_get_related_products($product->get_id()))), 'upsell_ids' => array_map('absint', $product->get_upsell_ids()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sell_ids()), 'categories' => wc_get_object_terms($product->get_id(), 'product_cat', 'name'), 'tags' => wc_get_object_terms($product->get_id(), 'product_tag', 'name'), 'images' => $this->get_images($product), 'featured_src' => wp_get_attachment_url(get_post_thumbnail_id($product->get_id())), 'attributes' => $this->get_attributes($product), 'downloads' => $this->get_downloads($product), 'download_limit' => $product->get_download_limit(), 'download_expiry' => $product->get_download_expiry(), 'download_type' => 'standard', 'purchase_note' => apply_filters('the_content', $product->get_purchase_note()), 'total_sales' => $product->get_total_sales(), 'variations' => array(), 'parent' => array());
 }
예제 #3
1
function woocs_product($ID, $attr, $currency = true)
{
    if (class_exists('WC_Product')) {
        $product = new WC_Product($ID);
        if ($attr == 'price_tax_inc') {
            $p = round($product->get_price_including_tax(), 2);
        } elseif ($attr == 'get_price_excluding_tax') {
            $p = round($product->get_price_excluding_tax(), 2);
        } elseif ($attr == 'get_price') {
            $p = round($product->get_price(), 2);
        } elseif ($attr == 'get_sale_price') {
            $p = round($product->get_sale_price(), 2);
        } elseif ($attr == 'get_regular_price') {
            $p = round($product->get_regular_price(), 2);
        } elseif ($attr == 'get_price_html') {
            $p = strip_tags($product->get_price_html());
        } elseif ($attr == 'is_in_stock') {
            $p = $product->is_in_stock();
        }
    }
    return $p;
}
예제 #4
0
 /**
  * Test updating a product.
  *
  * @since 2.7.0
  */
 function test_product_update()
 {
     $product = WC_Helper_Product::create_simple_product();
     $this->assertEquals('10', $product->get_regular_price());
     $product->set_regular_price(15);
     $product->save();
     // Reread from database
     $product = new WC_Product($product->get_id());
     $this->assertEquals('15', $product->get_regular_price());
 }
 public function get_base_product_price($id, $price)
 {
     if (!defined('WC_RBP_SHORTCODE_PRODUCT_BASE_PRICING')) {
         define('WC_RBP_SHORTCODE_PRODUCT_BASE_PRICING', true);
     }
     $product = new WC_Product($id);
     if ($price == 'product_regular_price') {
         return $product->get_regular_price();
     }
     if ($price == 'product_selling_price') {
         return $product->get_sale_price();
     }
 }
 /**
  * Get min/max composite regular price.
  *
  * @param  string $min_or_max
  * @return double
  */
 public function get_composite_regular_price($min_or_max = 'min', $display = false)
 {
     if ($this->is_priced_per_product()) {
         if (!$this->is_synced()) {
             $this->sync_composite();
         }
         $price = $min_or_max === 'min' ? $this->min_composite_regular_price : $this->max_composite_regular_price;
         if ($price && $display) {
             $display_price = WC_CP()->api->get_composited_product_price($this, $this->get_base_regular_price());
             foreach ($this->price_index['regular_price'][$min_or_max] as $component_id => $product_id) {
                 $component_data = $this->get_component_data($component_id);
                 $item_qty = $component_data['optional'] === 'yes' && $min_or_max === 'min' ? 0 : $component_data['quantity_' . $min_or_max];
                 if ($item_qty) {
                     $composited_product = $this->get_composited_product($component_id, $product_id);
                     $display_price += $item_qty * $composited_product->get_regular_price($min_or_max, true);
                 }
             }
             $price = $display_price;
         }
     } else {
         $price = parent::get_regular_price();
         if ($display) {
             $price = WC_CP_Core_Compatibility::is_wc_version_gte_2_4() ? parent::get_display_price($price) : WC_CP()->api->get_composited_product_price($this, $price);
         }
     }
     return $price;
 }
예제 #7
0
/**
 * Build a Google Shopping Content Product from a WC Product
 * @param WC_Product $wc_product
 * @return Google_Service_ShoppingContent_Product
 */
function woogle_build_product($wc_product)
{
    // Create Google Shopping Content Product
    require_once plugin_dir_path(woogle_get_plugin_file()) . 'vendor/google-api-php-client/src/Google/Service/ShoppingContent.php';
    $product = new Google_Service_ShoppingContent_Product();
    // Custom Attributes
    $product_custom_attributes = array();
    // Product identifiers
    $sku = $wc_product->get_sku();
    if (empty($sku)) {
        if ($wc_product->is_type('variation')) {
            $product->setOfferId($wc_product->variation_id);
        } else {
            $product->setOfferId($wc_product->id);
        }
    } else {
        $product->setOfferId($sku);
    }
    if ($wc_product->is_type('variation')) {
        $product->setItemGroupId($wc_product->parent->id);
    }
    $woocommerce_id_attribute = new Google_Service_ShoppingContent_ProductCustomAttribute();
    $woocommerce_id_attribute->setName('woocommerce_id');
    $woocommerce_id_attribute->setValue($wc_product->id);
    $woocommerce_id_attribute->setType('int');
    $product_custom_attributes[] = $woocommerce_id_attribute;
    // Title
    $woogle_title = get_post_meta($wc_product->id, '_woogle_title', true);
    if (!empty($woogle_title)) {
        $product->setTitle(html_entity_decode(strip_tags($woogle_title)));
    } else {
        $product->setTitle(html_entity_decode(strip_tags($wc_product->get_title())));
    }
    // Description
    $woogle_description = get_post_meta($wc_product->id, '_woogle_description', true);
    if (!empty($woogle_description)) {
        $product->setDescription(html_entity_decode(strip_tags($woogle_description)));
    } else {
        $product->setDescription(html_entity_decode(strip_tags($wc_product->post->post_content)));
    }
    $product->setLink($wc_product->get_permalink());
    $image = $wc_product->get_image();
    $post_thumbnail_id = get_post_thumbnail_id($wc_product->id);
    if ($post_thumbnail_id) {
        $image_src = wp_get_attachment_image_src($post_thumbnail_id);
        $product->setImageLink(@$image_src[0]);
    }
    $product->setContentLanguage(substr(get_locale(), 0, 2));
    $product->setTargetCountry(WC()->countries->get_base_country());
    $product->setChannel('online');
    $product->setAvailability($wc_product->is_in_stock() ? 'in stock' : 'out of stock');
    // Condition
    $condition = get_post_meta($wc_product->id, '_woogle_condition', true);
    if (!empty($condition)) {
        $product->setCondition($condition);
    } else {
        $product->setcondition('new');
    }
    // Category
    $category = get_post_meta($wc_product->id, '_woogle_category', true);
    if (!empty($category)) {
        $product->setGoogleProductCategory($category);
    }
    // Brand
    $brand = get_post_meta($wc_product->id, '_woogle_brand', true);
    if (!empty($brand)) {
        $product->setBrand($brand);
    }
    // GTIN
    $gtin = get_post_meta($wc_product->id, '_woogle_gtin', true);
    if (!empty($gtin)) {
        $product->setGtin($gtin);
    }
    // MPN
    $mpn = get_post_meta($wc_product->id, '_woogle_mpn', true);
    if (!empty($mpn)) {
        $product->setMpn($mpn);
    }
    if (empty($gtin) && empty($mpn)) {
        $product->setIdentifierExists(false);
    }
    // Price
    $price = new Google_Service_ShoppingContent_Price();
    $price->setValue($wc_product->get_regular_price());
    $price->setCurrency(get_woocommerce_currency());
    $product->setPrice($price);
    // Sale price
    $wc_sale_price = $wc_product->get_sale_price();
    if (!empty($wc_sale_price)) {
        $sale_price = new Google_Service_ShoppingContent_Price();
        $sale_price->setValue($wc_sale_price);
        $sale_price->setCurrency(get_woocommerce_currency());
        $product->setSalePrice($sale_price);
        $post_id = $wc_product->is_type('variation') ? $wc_product->variation_id : $wc_product->id;
        $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 (!empty($sale_price_dates_from) && !empty($sale_price_dates_to)) {
            $effective_date_start = date('c', intval($sale_price_dates_from));
            $effective_date_end = date('c', intval($sale_price_dates_to));
            $product->setSalePriceEffectiveDate("{$effective_date_start}/{$effective_date_end}");
        }
    }
    // Shipping fields
    // Shipping weight
    $wc_product_weight = $wc_product->get_weight();
    if (!empty($wc_product_weight)) {
        $shipping_weight = new Google_Service_ShoppingContent_ProductShippingWeight();
        $shipping_weight->setValue($wc_product_weight);
        $shipping_weight->setUnit(get_option('woocommerce_weight_unit', 'kg'));
        $product->setShippingWeight($shipping_weight);
    }
    // Shipping dimensions
    $wc_dimension_unit = get_option('woocommerce_dimension_unit', 'cm');
    $wc_product_length = $wc_product->get_length();
    if (!empty($wc_product_length)) {
        $dimension = new Google_Service_ShoppingContent_ProductShippingDimension();
        $dimension->setValue($wc_product_length);
        $dimension->setUnit($wc_dimension_unit);
        $product->setShippingLength($dimension);
    }
    $wc_product_width = $wc_product->get_width();
    if (!empty($wc_product_width)) {
        $dimension = new Google_Service_ShoppingContent_ProductShippingDimension();
        $dimension->setValue($wc_product_width);
        $dimension->setUnit($wc_dimension_unit);
        $product->setShippingWidth($dimension);
    }
    $wc_product_height = $wc_product->get_height();
    if (!empty($wc_product_height)) {
        $dimension = new Google_Service_ShoppingContent_ProductShippingDimension();
        $dimension->setValue($wc_product_height);
        $dimension->setUnit($wc_dimension_unit);
        $product->setShippingHeight($dimension);
    }
    // Attributes
    $color = null;
    $material = null;
    $pattern = null;
    $size = null;
    $age_group = null;
    $gender = null;
    $adult = null;
    if ($wc_product->is_type('variation')) {
        // Variable product
        $wc_variation_attributes = $wc_product->get_variation_attributes();
        foreach ($wc_variation_attributes as $name => $value) {
            if (!empty($value)) {
                $attribute = new Google_Service_ShoppingContent_ProductCustomAttribute();
                $attribute->setName($name);
                $attribute->setValue($value);
                $attribute->setType('text');
                $product_custom_attributes[] = $attribute;
                // Google attributes
                if (empty($color)) {
                    $color = woogle_maybe_get_attribute('color', $name, $value);
                }
                if (empty($material)) {
                    $material = woogle_maybe_get_attribute('material', $name, $value);
                }
                if (empty($pattern)) {
                    $pattern = woogle_maybe_get_attribute('pattern', $name, $value);
                }
                if (empty($size)) {
                    $size = woogle_maybe_get_attribute('size', $name, $value);
                }
                if (empty($age_group)) {
                    $age_group = woogle_maybe_get_attribute('age-group', $name, $value);
                }
                if (empty($gender)) {
                    $gender = woogle_maybe_get_attribute('gender', $name, $value);
                }
                if (empty($adult)) {
                    $adult = woogle_maybe_get_attribute('adult', $name, $value);
                }
            }
        }
    } else {
        // Simple product
        $wc_attributes = $wc_product->get_attributes();
        foreach ($wc_attributes as $name => $wc_attribute) {
            if ($wc_attribute['is_taxonomy']) {
                $term_values = array();
                $terms = wp_get_post_terms($wc_product->id, $name);
                foreach ($terms as $term) {
                    $term_values[] = $term->slug;
                }
                if (!empty($term_values)) {
                    $value = implode(',', $term_values);
                    $attribute = new Google_Service_ShoppingContent_ProductCustomAttribute();
                    $attribute->setName($name);
                    $attribute->setValue($value);
                    $attribute->setType('text');
                    $product_custom_attributes[] = $attribute;
                    // Google attributes
                    if (empty($color)) {
                        $color = woogle_maybe_get_attribute('color', $name, $value);
                    }
                    if (empty($material)) {
                        $material = woogle_maybe_get_attribute('material', $name, $value);
                    }
                    if (empty($pattern)) {
                        $pattern = woogle_maybe_get_attribute('pattern', $name, $value);
                    }
                    if (empty($size)) {
                        $size = woogle_maybe_get_attribute('size', $name, $value);
                    }
                    if (empty($age_group)) {
                        $age_group = woogle_maybe_get_attribute('age-group', $name, $value);
                    }
                    if (empty($gender)) {
                        $gender = woogle_maybe_get_attribute('gender', $name, $value);
                    }
                    if (empty($adult)) {
                        $adult = woogle_maybe_get_attribute('adult', $name, $value);
                    }
                }
            }
        }
    }
    /*
     * Physical properties
     */
    // Color
    if (empty($color)) {
        $color = get_post_meta($wc_product->id, '_woogle_color', true);
    }
    if (!empty($color)) {
        $product->setColor($color);
    }
    // Material
    if (empty($material)) {
        $material = get_post_meta($wc_product->id, '_woogle_material', true);
    }
    if (!empty($material)) {
        $product->setMaterial($material);
    }
    // Pattern
    if (empty($pattern)) {
        $pattern = get_post_meta($wc_product->id, '_woogle_pattern', true);
    }
    if (!empty($pattern)) {
        $product->setPattern($pattern);
    }
    // Size
    if (empty($size)) {
        $size = get_post_meta($wc_product->id, '_woogle_size', true);
    }
    if (!empty($size)) {
        $product->setSizes(explode(', ', $size));
        $product->setSizeSystem(WC()->countries->get_base_country());
    }
    /*
     * Target consumer
     */
    // Age Group
    if (empty($age_group)) {
        $age_group = get_post_meta($wc_product->id, '_woogle_age_group', true);
    }
    if (!empty($age_group)) {
        $product->setAgeGroup($age_group);
    }
    // Gender
    if (empty($gender)) {
        $gender = get_post_meta($wc_product->id, '_woogle_gender', true);
    }
    if (!empty($gender)) {
        $product->setGender($gender);
    }
    // Gender
    if (empty($adult)) {
        $adult = get_post_meta($wc_product->id, '_woogle_adult', true);
    }
    if (!empty($adult) && $adult != 'no') {
        $product->setAdult(true);
    }
    $product->setCustomAttributes($product_custom_attributes);
    return $product;
}
 /**
  * Get product data.
  *
  * @param WC_Product $product Product instance.
  * @return array
  */
 protected function get_product_data($product)
 {
     $data = array('id' => $product->get_id(), 'name' => $product->get_name(), 'slug' => $product->get_slug(), 'permalink' => $product->get_permalink(), 'date_created' => wc_rest_prepare_date_response($product->get_date_created()), 'date_modified' => wc_rest_prepare_date_response($product->get_date_modified()), 'type' => $product->get_type(), 'status' => $product->get_status(), 'featured' => $product->is_featured(), 'catalog_visibility' => $product->get_catalog_visibility(), 'description' => wpautop(do_shortcode($product->get_description())), 'short_description' => apply_filters('woocommerce_short_description', $product->get_short_description()), '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->get_date_on_sale_from() ? date('Y-m-d', $product->get_date_on_sale_from()) : '', 'date_on_sale_to' => $product->get_date_on_sale_to() ? date('Y-m-d', $product->get_date_on_sale_to()) : '', 'price_html' => $product->get_price_html(), 'on_sale' => $product->is_on_sale(), 'purchasable' => $product->is_purchasable(), 'total_sales' => $product->get_total_sales(), 'virtual' => $product->is_virtual(), 'downloadable' => $product->is_downloadable(), 'downloads' => $this->get_downloads($product), 'download_limit' => $product->get_download_limit(), 'download_expiry' => $product->get_download_expiry(), '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->get_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' => $product->get_shipping_class_id(), 'reviews_allowed' => $product->get_reviews_allowed(), 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => $product->get_rating_count(), 'related_ids' => array_map('absint', array_values(wc_get_related_products($product->get_id()))), 'upsell_ids' => array_map('absint', $product->get_upsell_ids()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sell_ids()), 'parent_id' => $product->get_parent_id(), 'purchase_note' => wpautop(do_shortcode(wp_kses_post($product->get_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' => $product->get_menu_order());
     return $data;
 }
예제 #9
0
 /**
  * Filter get_price() calls for bundled products to include discounts.
  *
  * @param  double       $price      unmodified price
  * @param  WC_Product   $product    the bundled product
  * @return double                   modified price
  */
 function get_price($price, $product)
 {
     if ($product->id !== $this->product->id || $price === '') {
         return $price;
     }
     if (!$this->is_priced_per_product()) {
         return 0;
     }
     if (apply_filters('woocommerce_bundled_item_discount_from_regular', true, $this)) {
         $regular_price = $product->get_regular_price();
     } else {
         $regular_price = $price;
     }
     $discount = $this->get_discount();
     $bundled_item_price = empty($discount) ? (double) $price : round((double) $regular_price * (100 - $discount) / 100, wc_bundles_get_price_decimals());
     $product->bundled_item_price = $bundled_item_price;
     return apply_filters('woocommerce_bundled_item_price', $bundled_item_price, $product, $discount);
 }
예제 #10
0
파일: Main.php 프로젝트: TakenCdosG/chefs
 /**
  * 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);
 }
예제 #11
0
 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;
 }
 /**
  * Bulk edit.
  *
  * @param integer $post_id
  * @param WC_Product $product
  */
 public function bulk_edit_save($post_id, $product)
 {
     $old_regular_price = $product->get_regular_price();
     $old_sale_price = $product->get_sale_price();
     // Save fields
     if (!empty($_REQUEST['change_weight']) && isset($_REQUEST['_weight'])) {
         $product->set_weight(wc_clean(stripslashes($_REQUEST['_weight'])));
     }
     if (!empty($_REQUEST['change_dimensions'])) {
         if (isset($_REQUEST['_length'])) {
             $product->set_length(wc_clean(stripslashes($_REQUEST['_length'])));
         }
         if (isset($_REQUEST['_width'])) {
             $product->set_width(wc_clean(stripslashes($_REQUEST['_width'])));
         }
         if (isset($_REQUEST['_height'])) {
             $product->set_height(wc_clean(stripslashes($_REQUEST['_height'])));
         }
     }
     if (!empty($_REQUEST['_tax_status'])) {
         $product->set_tax_status(wc_clean($_REQUEST['_tax_status']));
     }
     if (!empty($_REQUEST['_tax_class'])) {
         $tax_class = wc_clean($_REQUEST['_tax_class']);
         if ('standard' == $tax_class) {
             $tax_class = '';
         }
         $product->set_tax_class($tax_class);
     }
     if (!empty($_REQUEST['_shipping_class'])) {
         $shipping_class = '_no_shipping_class' == $_REQUEST['_shipping_class'] ? '' : wc_clean($_REQUEST['_shipping_class']);
         $shipping_class_id = $data_store->get_shipping_class_id_by_slug($shipping_class);
         if ($shipping_class_id) {
             $product->set_shipping_class_id($shipping_class_id);
         }
     }
     if (!empty($_REQUEST['_visibility'])) {
         $product->set_catalog_visibility(wc_clean($_REQUEST['_visibility']));
     }
     if (!empty($_REQUEST['_featured'])) {
         $product->set_featured(stripslashes($_REQUEST['_featured']));
     }
     // Sold Individually
     if (!empty($_REQUEST['_sold_individually'])) {
         if ('yes' === $_REQUEST['_sold_individually']) {
             $product->set_sold_individually('yes');
         } else {
             $product->set_sold_individually('');
         }
     }
     // Handle price - remove dates and set to lowest
     $change_price_product_types = apply_filters('woocommerce_bulk_edit_save_price_product_types', array('simple', 'external'));
     $can_product_type_change_price = false;
     foreach ($change_price_product_types as $product_type) {
         if ($product->is_type($product_type)) {
             $can_product_type_change_price = true;
             break;
         }
     }
     if ($can_product_type_change_price) {
         $price_changed = false;
         if (!empty($_REQUEST['change_regular_price'])) {
             $change_regular_price = absint($_REQUEST['change_regular_price']);
             $regular_price = esc_attr(stripslashes($_REQUEST['_regular_price']));
             switch ($change_regular_price) {
                 case 1:
                     $new_price = $regular_price;
                     break;
                 case 2:
                     if (strstr($regular_price, '%')) {
                         $percent = str_replace('%', '', $regular_price) / 100;
                         $new_price = $old_regular_price + round($old_regular_price * $percent, wc_get_price_decimals());
                     } else {
                         $new_price = $old_regular_price + $regular_price;
                     }
                     break;
                 case 3:
                     if (strstr($regular_price, '%')) {
                         $percent = str_replace('%', '', $regular_price) / 100;
                         $new_price = max(0, $old_regular_price - round($old_regular_price * $percent, wc_get_price_decimals()));
                     } else {
                         $new_price = max(0, $old_regular_price - $regular_price);
                     }
                     break;
                 default:
                     break;
             }
             if (isset($new_price) && $new_price != $old_regular_price) {
                 $price_changed = true;
                 $new_price = round($new_price, wc_get_price_decimals());
                 $product->set_regular_price($new_price);
             }
         }
         if (!empty($_REQUEST['change_sale_price'])) {
             $change_sale_price = absint($_REQUEST['change_sale_price']);
             $sale_price = esc_attr(stripslashes($_REQUEST['_sale_price']));
             switch ($change_sale_price) {
                 case 1:
                     $new_price = $sale_price;
                     break;
                 case 2:
                     if (strstr($sale_price, '%')) {
                         $percent = str_replace('%', '', $sale_price) / 100;
                         $new_price = $old_sale_price + $old_sale_price * $percent;
                     } else {
                         $new_price = $old_sale_price + $sale_price;
                     }
                     break;
                 case 3:
                     if (strstr($sale_price, '%')) {
                         $percent = str_replace('%', '', $sale_price) / 100;
                         $new_price = max(0, $old_sale_price - $old_sale_price * $percent);
                     } else {
                         $new_price = max(0, $old_sale_price - $sale_price);
                     }
                     break;
                 case 4:
                     if (strstr($sale_price, '%')) {
                         $percent = str_replace('%', '', $sale_price) / 100;
                         $new_price = max(0, $product->regular_price - $product->regular_price * $percent);
                     } else {
                         $new_price = max(0, $product->regular_price - $sale_price);
                     }
                     break;
                 default:
                     break;
             }
             if (isset($new_price) && $new_price != $old_sale_price) {
                 $price_changed = true;
                 $new_price = !empty($new_price) || '0' === $new_price ? round($new_price, wc_get_price_decimals()) : '';
                 $product->set_sale_price($new_price);
             }
         }
         if ($price_changed) {
             $product->set_date_on_sale_to('');
             $product->set_date_on_sale_from('');
             if ($product->get_regular_price() < $product->get_sale_price()) {
                 $product->set_sale_price('');
             }
         }
     }
     // Handle Stock Data
     $was_managing_stock = $product->get_manage_stock() ? 'yes' : 'no';
     $stock_status = $product->get_stock_status();
     $backorders = $product->get_backorders();
     $backorders = !empty($_REQUEST['_backorders']) ? wc_clean($_REQUEST['_backorders']) : $backorders;
     $stock_status = !empty($_REQUEST['_stock_status']) ? wc_clean($_REQUEST['_stock_status']) : $stock_status;
     if (!empty($_REQUEST['_manage_stock'])) {
         $manage_stock = 'yes' === wc_clean($_REQUEST['_manage_stock']) && 'grouped' !== $product->product_type ? 'yes' : 'no';
     } else {
         $manage_stock = $was_managing_stock;
     }
     $stock_amount = 'yes' === $manage_stock && isset($_REQUEST['_change_stock']) ? wc_stock_amount($_REQUEST['_change_stock']) : '';
     if ('yes' === get_option('woocommerce_manage_stock')) {
         // Apply product type constraints to stock status
         if ($product->is_type('external')) {
             // External always in stock
             $stock_status = 'instock';
         } elseif ($product->is_type('variable')) {
             // Stock status is always determined by children
             foreach ($product->get_children() as $child_id) {
                 $child = wc_get_product($child_id);
                 if (!$product->get_manage_stock()) {
                     $child->set_stock_status($stock_status);
                     $child->save();
                 }
             }
             $product = WC_Product_Variable::sync($product, false);
         }
         $product->set_manage_stock($manage_stock);
         $product->set_backorders($backorders);
         $product->save();
         if (!$product->is_type('variable')) {
             wc_update_product_stock_status($post_id, $stock_status);
         }
         wc_update_product_stock($post_id, $stock_amount);
     } else {
         $product->save();
         wc_update_product_stock_status($post_id, $stock_status);
     }
     do_action('woocommerce_product_bulk_edit_save', $product);
 }
예제 #13
0
 /**
  * Getter for max_bundle_regular_price.
  *
  * @return double
  */
 public function get_max_bundle_regular_price()
 {
     if ($this->is_priced_per_product()) {
         if (!$this->is_synced()) {
             $this->sync_bundle();
         }
         $price = $this->max_bundle_regular_price;
     } else {
         $price = parent::get_regular_price();
     }
     return $price;
 }
 /**
  * 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;
 }
 /**
  * Get min/max bundle regular price.
  *
  * @param  string $min_or_max
  * @return double
  */
 public function get_bundle_regular_price($min_or_max = 'min', $display = false)
 {
     if ($this->is_priced_per_product()) {
         if (!$this->is_synced()) {
             $this->sync_bundle();
         }
         $price = $min_or_max === 'min' ? $this->min_bundle_regular_price : $this->max_bundle_regular_price;
         if ($price && $display) {
             $display_price = WC_PB_Helpers::get_product_display_price($this, $this->get_base_regular_price());
             foreach ($this->bundled_items as $bundled_item) {
                 $bundled_item_qty = $this->bundled_quantities_index[$min_or_max][$bundled_item->item_id];
                 if ($bundled_item_qty) {
                     $display_price += $bundled_item_qty * $bundled_item->get_bundled_item_regular_price($min_or_max, true);
                 }
             }
             $price = $display_price;
         }
     } else {
         $price = parent::get_regular_price();
         if ($display) {
             $price = WC_PB_Core_Compatibility::is_wc_version_gte_2_4() ? parent::get_display_price($price) : WC_PB_Helpers::get_product_display_price($this, $price);
         }
     }
     return $price;
 }
예제 #16
0
파일: Main.php 프로젝트: TakenCdosG/chefs
 /**
  * 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);
 }
 /**
  * Filter get_sale_price() calls to take price overrides into account.
  *
  * @param  double       $price      unmodified reg price
  * @param  WC_Product   $product    the bundled product
  * @return double                   modified reg price
  */
 public static function filter_get_sale_price($sale_price, $product)
 {
     $subscription_scheme = self::$price_overriding_scheme;
     if ($subscription_scheme) {
         self::$price_overriding_scheme = false;
         $prices_array = array('price' => $product->get_price(), 'regular_price' => $product->get_regular_price(), 'sale_price' => $sale_price);
         self::$price_overriding_scheme = $subscription_scheme;
         $overridden_prices = self::get_subscription_scheme_prices($prices_array, $subscription_scheme);
         $sale_price = $overridden_prices['sale_price'];
     }
     return $sale_price;
 }
예제 #18
0
 /**
  * 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);
 }
예제 #19
0
 /**
  * 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;
 }
예제 #20
0
 /**
  * Filters get_price to include component discounts.
  *
  * @param  double     $price
  * @param  WC_Product $product
  * @return string
  */
 public function filter_show_product_get_price($price, $product)
 {
     if (!empty($this->filter_params)) {
         if ($price === '') {
             return $price;
         }
         if (!$this->filter_params['per_product_pricing']) {
             return (double) 0;
         }
         if (isset($product->bundled_item_price)) {
             $regular_price = $product->bundled_item_price;
         } else {
             if (apply_filters('woocommerce_composited_product_discount_from_regular', true, $this->filter_params['component_id'], $this->filter_params['composite_id'])) {
                 $regular_price = $product->get_regular_price();
             } else {
                 $regular_price = $price;
             }
         }
         $discount = $this->filter_params['discount'];
         return empty($discount) ? $price : round((double) $regular_price * (100 - $discount) / 100, $this->wc_option_price_num_decimals);
     }
     return $price;
 }
 /**
  * Overrides get_regular_price to return base price in static price mode.
  *
  * @return double
  */
 public function get_regular_price()
 {
     if ($this->is_priced_per_product()) {
         return apply_filters('woocommerce_composite_get_regular_price', $this->get_base_regular_price(), $this);
     } else {
         return parent::get_regular_price();
     }
 }
 /**
  * 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());
 }
 /**
  * Filter get_price() calls for bundled products to include discounts.
  *
  * @param  double       $price      unmodified price
  * @param  WC_Product   $product    the bundled product
  * @return double                   modified price
  */
 public static function filter_get_price($price, $product)
 {
     $bundled_item = self::$bundled_item;
     if ($bundled_item) {
         if ($price === '') {
             return $price;
         }
         if (!$bundled_item->is_priced_per_product()) {
             return 0;
         }
         if (apply_filters('woocommerce_bundled_item_discount_from_regular', true, $bundled_item)) {
             $regular_price = $product->get_regular_price();
         } else {
             $regular_price = $price;
         }
         $discount = $bundled_item->get_discount();
         $bundled_item_price = empty($discount) ? $price : (empty($regular_price) ? $regular_price : round((double) $regular_price * (100 - $discount) / 100, WC_PB_Core_Compatibility::wc_get_price_decimals()));
         $product->bundled_item_price = $bundled_item_price;
         $price = apply_filters('woocommerce_bundled_item_price', $bundled_item_price, $product, $discount, $bundled_item);
     }
     return $price;
 }