get_price() public method

Returns the product's active price.
public get_price ( string $context = 'view' ) : string
$context string
return 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());
 }
 /**
  * Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting.
  * Should be safe to remove when we drop WC 2.2 compatibility
  *
  * @param  WC_Product $product the product object
  * @param  string     $price   to calculate, left blank to just use get_price()
  * @param  integer    $qty     passed on to get_price_including_tax() or get_price_excluding_tax()
  * @return string
  */
 public static function get_product_display_price($product, $price = '', $qty = 1)
 {
     if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
         return $product->get_display_price($price, $qty);
     } else {
         if ($price === '') {
             $price = $product->get_price();
         }
         $tax_display_mode = get_option('woocommerce_tax_display_shop');
         $display_price = $tax_display_mode == 'incl' ? $product->get_price_including_tax($qty, $price) : $product->get_price_excluding_tax($qty, $price);
         return $display_price;
     }
 }
Ejemplo n.º 4
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;
}
 /**
  * Get min/max composite price excluding tax.
  *
  * @return double
  */
 public function get_composite_price_excluding_tax($min_or_max = 'min')
 {
     if ($this->is_priced_per_product()) {
         if (!$this->is_synced()) {
             $this->sync_composite();
         }
         $property = $min_or_max . '_composite_price_excl_tax';
         if ($this->{$property} !== false) {
             return $this->{$property};
         }
         $price = $min_or_max === 'min' ? $this->min_composite_price : $this->max_composite_price;
         if ($price) {
             $this->{$property} = $this->get_price_excluding_tax(1, $this->get_base_price());
             foreach ($this->price_index['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);
                     $this->{$property} += $item_qty * $composited_product->get_price_excluding_tax($min_or_max);
                 }
             }
             $price = $this->{$property};
         }
     } else {
         $price = parent::get_price_excluding_tax(1, parent::get_price());
     }
     return $price;
 }
 /**
  * Get variation attribute values
  * 
  * @return string containing the formatted price
  */
 function get_price_html()
 {
     if ($this->variation_has_price || $this->variation_has_sale_price) {
         $price = '';
         if ($this->price !== '') {
             if ($this->variation_has_sale_price) {
                 $price .= '<del>' . woocommerce_price($this->regular_price) . '</del> <ins>' . woocommerce_price($this->sale_price) . '</ins>';
                 $price = apply_filters('woocommerce_variation_sale_price_html', $price, $this);
             } else {
                 $price .= woocommerce_price($this->price);
                 $price = apply_filters('woocommerce_variation_price_html', $price, $this);
             }
         }
         return $price;
     } else {
         return woocommerce_price(parent::get_price());
     }
 }
Ejemplo n.º 7
1
 /**
  * Get the product row subtotal.
  *
  * Gets the tax etc to avoid rounding issues.
  *
  * When on the checkout (review order), this will get the subtotal based on the customer's tax rate rather than the base rate.
  *
  * @param WC_Product $_product
  * @param int $quantity
  * @return string formatted price
  */
 public function get_product_subtotal($_product, $quantity)
 {
     $price = $_product->get_price();
     $taxable = $_product->is_taxable();
     // Taxable
     if ($taxable) {
         if ($this->tax_display_cart == 'excl') {
             $row_price = $_product->get_price_excluding_tax($quantity);
             $product_subtotal = wc_price($row_price);
             if ($this->prices_include_tax && $this->tax_total > 0) {
                 $product_subtotal .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
             }
         } else {
             $row_price = $_product->get_price_including_tax($quantity);
             $product_subtotal = wc_price($row_price);
             if (!$this->prices_include_tax && $this->tax_total > 0) {
                 $product_subtotal .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
             }
         }
         // Non-taxable
     } else {
         $row_price = $price * $quantity;
         $product_subtotal = wc_price($row_price);
     }
     return apply_filters('woocommerce_cart_product_subtotal', $product_subtotal, $_product, $quantity, $this);
 }
Ejemplo n.º 8
0
function hocwp_wc_get_product_price($post_id = null)
{
    if (!hocwp_id_number_valid($post_id)) {
        $post_id = get_the_ID();
    }
    global $product;
    $h_product = $product;
    if (!is_a($h_product, 'WC_Product')) {
        $h_product = new WC_Product($post_id);
    }
    return $h_product->get_price();
}
/**
 * Add the product price to the individual line item entry
 *
 * @param array      $line_item    the original line item data
 * @param array      $item         WC order item data
 * @param WC_Product $product      the product
 * @return array updated line item data
 */
function sv_wc_csv_export_order_line_item_price($line_item, $item, $product)
{
    $new_line_item = array();
    foreach ($line_item as $key => $data) {
        $new_line_item[$key] = $data;
        // add this in the JSON / pipe-format after the SKU
        if ('sku' === $key) {
            $new_line_item['price'] = wc_format_decimal($product->get_price(), 2);
        }
    }
    return $new_line_item;
}
function woocommerce_gravityforms_get_updated_price()
{
    global $woocommerce;
    header('Cache-Control: no-cache, must-revalidate');
    header('Content-type: application/json');
    $variation_id = isset($_POST['variation_id']) ? $_POST['variation_id'] : '';
    $product_id = isset($_POST['product_id']) ? $_POST['product_id'] : 0;
    $gform_total = isset($_POST['gform_total']) ? $_POST['gform_total'] : 0;
    $product_data = null;
    if (function_exists('get_product')) {
        $product_data = get_product($variation_id > 0 ? $variation_id : $product_id);
    } else {
        if ($variation_id > 0) {
            $product_data = new WC_Product_Variation($variation_id);
        } else {
            $product_data = new WC_Product($product_id);
        }
    }
    $discount_price = false;
    $gforms_discount_price = false;
    $base_price = $product_data->get_price();
    if (class_exists('WC_Dynamic_Pricing')) {
        $working_price = $base_price;
        $dynamic_pricing = WC_Dynamic_Pricing::instance();
        foreach ($dynamic_pricing->modules as $module) {
            if ($module->module_type == 'simple') {
                //Make sure we are using the price that was just discounted.
                $working_price = $discount_price ? $discount_price : $base_price;
                $working_price = $module->get_product_working_price($working_price, $product_data);
                if (floatval($working_price)) {
                    $discount_price = $module->get_discounted_price_for_shop($product_data, $working_price);
                }
            }
        }
        $gforms_base_price = $base_price + $gform_total;
        $gforms_working_price = $base_price + $gform_total;
        foreach ($dynamic_pricing->modules as $module) {
            if ($module->module_type == 'simple') {
                //Make sure we are using the price that was just discounted.
                $gforms_working_price = $gforms_discount_price ? $gforms_discount_price : $gforms_base_price;
                $gforms_working_price = $module->get_product_working_price($gforms_working_price, $product_data);
                if (floatval($gforms_working_price)) {
                    $gforms_discount_price = $module->get_discounted_price_for_shop($product_data, $gforms_working_price);
                }
            }
        }
    }
    $price = $discount_price ? $discount_price : $base_price;
    $gform_final_total = $gforms_discount_price ? $gforms_discount_price : $price + $gform_total;
    $result = array('formattedBasePrice' => apply_filters('woocommerce_gform_base_price', woocommerce_price($price), $product_data), 'formattedTotalPrice' => apply_filters('woocommerce_gform_total_price', woocommerce_price($gform_final_total), $product_data), 'formattedVariationTotal' => apply_filters('woocommerce_gform_variation_total_price', woocommerce_price($gform_total), $product_data));
    echo json_encode($result);
    die;
}
Ejemplo n.º 11
0
 function export_products()
 {
     $api_key = get_option('pixelshop_key');
     $path = apply_filters('pixelshop/get_info', 'path');
     include_once $path . 'core/api.php';
     if (isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'export_products') && $api_key !== false) {
         $api = new API($api_key);
         $args = array('post_type' => 'product', 'orderby' => $orderby, 'post_status' => 'publish', 'posts_per_page' => -1);
         $the_query = new WP_Query($args);
         $products = [];
         $i = 0;
         while ($the_query->have_posts()) {
             $i++;
             $the_query->the_post();
             $product = new WC_Product($the_query->post->ID);
             $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($the_query->post->ID), array(250, 250));
             $products[$i] = ["sync_id" => $the_query->post->ID, "link" => get_permalink($the_query->post->ID), "title" => get_the_title(), "description" => get_the_excerpt(), "price" => $product->get_price(), "sku" => $product->get_sku(), "thumb" => $thumb[0], "tags" => ''];
             if (!isset($product->get_tags()->errors)) {
                 $tags = wp_get_object_terms($the_query->post->ID, 'product_tag');
                 $tags_list = '';
                 foreach ($tags as $tag) {
                     $tags_list .= $tag->name . ', ';
                 }
                 $products[$i]["tags"] = substr($tags_list, 0, -2);
             }
         }
         $export = $api->export->products($products);
         if (isset($export['error'])) {
             add_action('admin_notices', array($this, 'api_key_invalid'));
         } else {
             add_option('pixelshop_message', $export, '', 'yes');
             $time = 60 * 60 * 24;
             if (get_option('pxs_last_export') === false) {
                 add_option('pxs_last_export', time() + $time, '', 'no');
             } else {
                 update_option('pxs_last_export', time() + $time);
             }
         }
     }
 }
Ejemplo n.º 12
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);
 }
Ejemplo n.º 13
0
                    ?>
</span>
						</div>
						<?php 
                }
                ?>
					<?php 
            } else {
                ?>
						<div class="et-price-button et-product-on-sale">
							<span class="et-price-before"><del><?php 
                echo woocommerce_price($et_price_before);
                ?>
</del></span>
							<span class="et-price-sale"><?php 
                echo woocommerce_price($product->get_price());
                ?>
</span>
						</div>
					<?php 
            }
            ?>

						<?php 
            woocommerce_show_product_sale_flash($post, $product);
            ?>
					</li>
		<?php 
        }
        ?>
				</ul>
Ejemplo n.º 14
0
 /**
  * Get the shop price of a product incl or excl tax, depending on the 'woocommerce_tax_display_shop' setting.
  *
  * @param  WC_Product $product
  * @param  double $price
  * @return double
  */
 public function get_composited_product_price($product, $price = '')
 {
     if ($price === '') {
         $price = $product->get_price();
     }
     if ($this->wc_option_tax_display_shop === 'excl') {
         $product_price = $product->get_price_excluding_tax(1, $price);
     } else {
         $product_price = $product->get_price_including_tax(1, $price);
     }
     return $product_price;
 }
Ejemplo n.º 15
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;
 }
 /**
  * Make product whose price is set as zero but is for purchasing credit, purchasable
  *
  * @param boolean $purchasable
  * @param WC_Product $product
  * @return boolean $purchasable
  */
 public function make_product_purchasable($purchasable, $product)
 {
     $coupons = get_post_meta($product->id, '_coupon_title', true);
     if (!empty($coupons) && $product instanceof WC_Product && $product->get_price() === '' && $this->is_coupon_amount_pick_from_product_price($coupons) && !($product->get_price() > 0)) {
         return true;
     }
     return $purchasable;
 }
Ejemplo n.º 17
0
 /**
  * Add a product to the cart
  *
  * @param   string	product_id	contains the id of the product to add to the cart
  * @param   string	quantity	contains the quantity of the item to add
  * @param   int     variation_id
  * @param   array   variation attribute values
  */
 function add_to_cart($product_id, $quantity = 1, $variation_id = '', $variation = '')
 {
     global $woocommerce;
     if ($quantity < 1) {
         return false;
     }
     // Load cart item data - may be added by other plugins
     $cart_item_data = (array) apply_filters('woocommerce_add_cart_item_data', array(), $product_id);
     // Generate a ID based on product ID, variation ID, variation data, and other cart item data
     $cart_id = $this->generate_cart_id($product_id, $variation_id, $variation, $cart_item_data);
     // See if this product and its options is already in the cart
     $cart_item_key = $this->find_product_in_cart($cart_id);
     if ($variation_id > 0) {
         $product_data = new WC_Product_Variation($variation_id);
     } else {
         $product_data = new WC_Product($product_id);
     }
     // Type/Exists check
     if ($product_data->is_type('external') || !$product_data->exists()) {
         $woocommerce->add_error(__('This product cannot be purchased.', 'woocommerce'));
         return false;
     }
     // Price set check
     if ($product_data->get_price() === '') {
         $woocommerce->add_error(__('This product cannot be purchased - the price is not yet set.', 'woocommerce'));
         return false;
     }
     // Stock check - only check if we're managing stock and backorders are not allowed
     if (!$product_data->has_enough_stock($quantity)) {
         $woocommerce->add_error(sprintf(__('You cannot add that amount to the cart since there is not enough stock. We have %s in stock.', 'woocommerce'), $product_data->get_stock_quantity()));
         return false;
     } elseif (!$product_data->is_in_stock()) {
         $woocommerce->add_error(__('You cannot add that product to the cart since the product is out of stock.', 'woocommerce'));
         return false;
     }
     if ($cart_item_key) {
         $quantity = $quantity + $this->cart_contents[$cart_item_key]['quantity'];
         // Stock check - this time accounting for whats already in-cart
         if (!$product_data->has_enough_stock($quantity)) {
             $woocommerce->add_error(sprintf(__('You cannot add that amount to the cart since there is not enough stock. We have %s in stock and you already have %s in your cart.', 'woocommerce'), $product_data->get_stock_quantity(), $this->cart_contents[$cart_item_key]['quantity']));
             return false;
         } elseif (!$product_data->is_in_stock()) {
             $woocommerce->add_error(__('You cannot add that product to the cart since the product is out of stock.', 'woocommerce'));
             return false;
         }
         $this->set_quantity($cart_item_key, $quantity);
     } else {
         // Add item after merging with $cart_item_data - hook to allow plugins to modify cart item
         $this->cart_contents[$cart_id] = apply_filters('woocommerce_add_cart_item', array_merge($cart_item_data, array('product_id' => $product_id, 'variation_id' => $variation_id, 'variation' => $variation, 'quantity' => $quantity, 'data' => $product_data)));
     }
     $this->set_session();
     return true;
 }
/**
 * Composited Simple product price.
 *
 * @param  WC_Product           $product
 * @param  string               $component_id
 * @param  WC_Product_Composite $composite
 * @return void
 */
function wc_cp_composited_product_price($product, $component_id, $composite)
{
    if ($product->product_type === 'simple') {
        if ($composite->is_priced_per_product() && $product->get_price() !== '') {
            wc_get_template('composited-product/price.php', array('product' => $product), '', WC_CP()->plugin_path() . '/templates/');
        }
    }
}
 /**
  * Calculate the item price based on the given measurements
  *
  * @since 3.1.3
  * @param WC_Product $product the product
  * @param float $measurement_needed_value the total measurement needed
  * @param string $measurement_needed_value_unit the unit of $measurement_needed_value
  * @return float the calculated price
  */
 public static function calculate_price($product, $measurement_needed_value, $measurement_needed_value_unit)
 {
     $price = $product->get_price();
     // get the parent product if there is one
     $_product = 'WC_Product_Variation' == get_class($product) ? $product->parent : $product;
     if (self::pricing_calculator_enabled($_product)) {
         $settings = new WC_Price_Calculator_Settings($_product);
         $measurement_needed = new WC_Price_Calculator_Measurement($measurement_needed_value_unit, (double) $measurement_needed_value);
         // if this calculator uses pricing rules, retrieve the price based on the product measurements
         if ($settings->pricing_rules_enabled()) {
             $product->price = $settings->get_pricing_rules_price($measurement_needed);
         }
         // calculate the price
         $price = $product->get_price() * $measurement_needed->get_value($settings->get_pricing_unit());
         // is there a minimum price to use?
         if (WC_Price_Calculator_Product::get_product_meta($product, 'wc_measurement_price_calculator_min_price') > $price) {
             $price = WC_Price_Calculator_Product::get_product_meta($product, 'wc_measurement_price_calculator_min_price');
         }
     }
     // return the final price
     return $price;
 }
Ejemplo n.º 20
0
require_once "../../../wp-config.php";
if (isset($_POST['productid'])) {
    global $wpdb;
    global $current_user;
    global $translate;
    global $woocommerce;
    // Get current user credits balance
    $getUserCredit = getUserCredit(get_current_user_id());
    // Get current product
    $product_id = mysql_real_escape_string($_POST['productid']);
    if ($product_id == 'undefined') {
        $product_id = '';
    }
    if (!empty($product_id)) {
        $product = new WC_Product($product_id);
        $productPrice = $product->get_price();
    }
    // Get the variant of the product if set
    $variation_id = mysql_real_escape_string($_POST['variationid']);
    if ($variation_id == 'undefined') {
        $variation_id = '';
    }
    if (!empty($variation_id)) {
        $variation = new WC_Product_Variation($variation_id);
        $productPrice = $variation->get_price();
    }
    // If user has required ammount of credits then continue
    if ($getUserCredit >= $productPrice) {
        get_currentuserinfo();
        // Save the purchase to the database and update credits balance of the user
        $sql = $wpdb->query("UPDATE `" . $wpdb->prefix . "woocredit_users` SET credit = '" . ($getUserCredit - $productPrice) . "' where user_id=" . get_current_user_id());
/**
 * Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting.
 * @since  2.7.0
 * @param  WC_Product $product
 * @param  array $args
 * @return float
 */
function wc_get_price_to_display($product, $args = array())
{
    $args = wp_parse_args($args, array('qty' => 1, 'price' => $product->get_price()));
    $price = $args['price'];
    $qty = $args['qty'];
    return 'incl' === get_option('woocommerce_tax_display_shop') ? wc_get_price_including_tax($product, array('qty' => $qty, 'price' => $price)) : wc_get_price_excluding_tax($product, array('qty' => $qty, 'price' => $price));
}
Ejemplo n.º 22
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;
 }
Ejemplo n.º 23
0
    if (in_array('yith-woocommerce-wishlist/init.php', apply_filters('active_plugins', get_option('active_plugins')))) {
        ?>
 
                    <?php 
        echo do_shortcode('[yith_wcwl_add_to_wishlist]');
        ?>
 
                <?php 
    }
    ?>
                                       
            </p>            
        </div>
            <div class="price_col">
                <?php 
    if ($product->get_price() != '') {
        ?>
           
                <p><span class="price_count"><?php 
        echo $product->get_price_html();
        ?>
</span></p>
                <?php 
    }
    ?>
  
                <?php 
    if (!empty($term_brand_image['brand_image'])) {
        ?>
                              
                <div class="aff_tag">
 /**
  * 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;
 }
Ejemplo n.º 25
0
 /**
  * Process the payment and return the result
  *
  * @access public
  * @param int $order_id
  * @return array
  */
 function process_payment($order_id)
 {
     global $woocommerce;
     $order = new WC_Order($order_id);
     $token = $_POST['payfortToken'];
     try {
         if (empty($token)) {
             $error_msg = __('Please make sure your card details have been entered correctly.', 'woocommerce');
             throw new Start_Error($error_msg);
         }
         $charge_description = $order->id . ": WooCommerce charge for " . $order->billing_email;
         $order_items = $order->get_items();
         $order_items_array_full = array();
         $user_info = wp_get_current_user();
         $user_name = $user_info->user_login;
         $udata = get_userdata($user_info->ID);
         if (isset($udata->user_registered)) {
             $registered_at = date(DATE_ISO8601, strtotime($udata->user_registered));
         } else {
             $registered_at = date(DATE_ISO8601, strtotime(date("Y-m-d H:i:s")));
         }
         foreach ($order_items as $key => $items) {
             $itemClass = new WC_Product($items['product_id']);
             $order_items_array['title'] = $items['name'];
             $order_items_array['amount'] = round($itemClass->get_price(), 2) * $this->currency_multiplier[get_woocommerce_currency()];
             $order_items_array['quantity'] = $items['qty'];
             array_push($order_items_array_full, $order_items_array);
         }
         $billing_address = array("first_name" => $order->billing_first_name, "last_name" => $order->billing_last_name, "country" => $order->billing_country, "city" => $order->billing_city, "address_1" => $order->billing_address_1, "address_2" => $order->billing_address_2, "phone" => $order->billing_phone, "postcode" => $order->billing_postcode);
         $shipping_address = array("first_name" => $order->shipping_first_name, "last_name" => $order->shipping_last_name, "country" => $order->shipping_country, "city" => $order->shipping_city, "address_1" => $order->shipping_address_1, "address_2" => $order->shipping_address_2, "phone" => $order->shipping_phone, "postcode" => $order->shipping_postcode);
         $shopping_cart_array = array('user_name' => $user_name, 'registered_at' => $registered_at, 'items' => $order_items_array_full, 'billing_address' => $billing_address, 'shipping_address' => $shipping_address);
         $charge_args = array('description' => $charge_description, 'card' => $token, 'currency' => strtoupper(get_woocommerce_currency()), 'email' => $order->billing_email, 'ip' => $_SERVER['REMOTE_ADDR'], 'amount' => $order->get_total() * $this->currency_multiplier[get_woocommerce_currency()], 'shopping_cart' => $shopping_cart_array, 'shipping_amount' => round($order->get_total_shipping(), 2) * $this->currency_multiplier[get_woocommerce_currency()], 'metadata' => array('reference_id' => $order_id));
         if ($this->test_mode == 'yes') {
             Start::setApiKey($this->test_secret_key);
         } else {
             Start::setApiKey($this->live_secret_key);
         }
         $start_plugin_data = get_file_data('wp-content/plugins/payfort/woocommerce-payfort.php', array('Version'), 'plugin');
         $woo_plugin_data = get_file_data('wp-content/plugins/woocommerce/woocommerce.php', array('Version'), 'plugin');
         $userAgent = 'WooCommerce ' . $woo_plugin_data['0'] . ' / Start Plugin ' . $start_plugin_data['0'];
         Start::setUserAgent($userAgent);
         $charge = Start_Charge::create($charge_args);
         // No exceptions? Yaay, all done!
         $order->payment_complete();
         return array('result' => 'success', 'redirect' => $this->get_return_url($order));
     } catch (Start_Error $e) {
         // TODO: Can we get the extra params (so the error is more apparent)?
         // e.g. Instead of "request params are invalid", we get
         // "extras":{"amount":["minimum amount (in the smallest currency unit) is 185 for AED"]
         $error_code = $e->getErrorCode();
         if ($error_code === "card_declined") {
             $message = __('Error: ', 'woothemes') . $e->getMessage() . " Please, try with another card";
         } else {
             $message = __('Error: ', 'woothemes') . $e->getMessage();
         }
         // If function should we use?
         if (function_exists("wc_add_notice")) {
             // Use the new version of the add_error method
             wc_add_notice($message, 'error');
         } else {
             // Use the old version
             $woocommerce->add_error($message);
         }
         // we raise 'update_checkout' event for javscript
         // to remove card token
         WC()->session->set('refresh_totals', true);
         return array('result' => 'fail', 'redirect' => '');
     }
 }
/**
 * Get the price suffix for a product if needed.
 * @since  2.7.0
 * @param  WC_Product  $product
 * @param  string  $price
 * @param  integer $qty
 * @return string
 */
function wc_get_price_suffix($product, $price = '', $qty = 1)
{
    if (($price_display_suffix = get_option('woocommerce_price_display_suffix')) && wc_tax_enabled()) {
        $price = '' === $price ? $product->get_price() : $price;
        $price_display_suffix = ' <small class="woocommerce-price-suffix">' . wp_kses_post($price_display_suffix) . '</small>';
        $find = array('{price_including_tax}', '{price_excluding_tax}');
        $replace = array(wc_price(wc_get_price_including_tax($product, array('qty' => $qty, 'price' => $price))), wc_price(wc_get_price_excluding_tax($product, array('qty' => $qty, 'price' => $price))));
        $price_display_suffix = str_replace($find, $replace, $price_display_suffix);
    } else {
        $price_display_suffix = '';
    }
    return apply_filters('woocommerce_get_price_suffix', $price_display_suffix, $product);
}
    function get_form($options)
    {
        global $woocommerce;
        $product = null;
        if (function_exists('get_product')) {
            $product = get_product($this->product_id);
        } else {
            $product = new WC_Product($this->product_id);
        }
        extract(shortcode_atts(array('display_title' => true, 'display_description' => true, 'display_inactive' => false, 'field_values' => false, 'ajax' => false, 'tabindex' => 1, 'label_subtotal' => __('Subtotal', 'wc_gf_addons'), 'label_options' => __('Options', 'wc_gf_addons'), 'label_total' => __('Total', 'wc_gf_addons'), 'disable_label_subtotal' => 'no', 'disable_label_options' => 'no', 'disable_label_total' => 'no', 'disable_calculations' => 'no'), $options));
        //Get the form meta so we can make sure the form exists.
        $form_meta = RGFormsModel::get_form_meta($this->form_id);
        if (!empty($form_meta)) {
            if (!empty($_POST)) {
                $_POST['gform_submit'] = isset($_POST['gform_old_submit']) ? $_POST['gform_old_submit'] : '';
                $_POST['gform_old_submit'] = $_POST['gform_submit'];
            }
            $form = RGForms::get_form($this->form_id, $display_title, $display_description, $display_inactive, $field_values, $ajax, $tabindex);
            unset($_POST['gform_submit']);
            $form = str_replace('</form>', '', $form);
            $form = str_replace('gform_submit', 'gform_old_submit', $form);
            $this->current_page = GFFormDisplay::get_current_page($this->form_id);
            $this->next_page = $this->current_page + 1;
            $this->previous_page = $this->current_page - 1;
            $this->next_page = $this->next_page > $this->get_max_page_number($form_meta) ? 0 : $this->next_page;
            if ($product->product_type == 'variable' || $product->product_type == 'variable-subscription') {
                echo '<div class="gform_variation_wrapper gform_wrapper single_variation_wrap">';
            } else {
                echo '<div class="gform_variation_wrapper gform_wrapper">';
            }
            if ($product->is_type('variable')) {
                //echo '<input type="hidden" name="add-to-cart" value="variation" />';
                echo '<input type="hidden" id="product_id" name="product_id" value="' . $this->product_id . '" />';
            } elseif ($product->has_child()) {
                //echo '<input type="hidden" name="add-to-cart" value="group" />';
                echo '<input type="hidden" id="product_id" name="product_id" value="' . $this->product_id . '" />';
            } else {
                //echo '<input type="hidden" name="add-to-cart" value="' . $this->product_id . '" />';
                echo '<input type="hidden" id="product_id" name="product_id" value="' . $this->product_id . '" />';
            }
            if (wc_is_21x()) {
                wp_nonce_field('add_to_cart');
            } else {
                $woocommerce->nonce_field('add_to_cart');
            }
            echo '<a id="_form_' . $this->form_id . '" href="#_form_' . $this->form_id . '" class="gform_anchor"></a>';
            echo $form;
            echo '<input type="hidden" name="gform_form_id" id="gform_form_id" value="' . $this->form_id . '" />';
            echo '<input type="hidden" id="woocommerce_get_action" value="" />';
            echo '<input type="hidden" id="woocommerce_product_base_price" value="' . $product->get_price() . '" />';
            $description_class = rgar($form_meta, "descriptionPlacement") == "above" ? "description_above" : "description_below";
            ?>

			<?php 
            $this->on_print_scripts();
            if ($disable_calculations == 'no') {
                ?>

				<div class="product_totals">
					<ul id="gform_totals_<?php 
                echo $this->form_id;
                ?>
" class="gform_fields <?php 
                echo $form_meta['labelPlacement'] . ' ' . $description_class;
                ?>
">
						<li class="gfield" <?php 
                if ($disable_label_subtotal == 'yes') {
                    echo 'style="display:none;"';
                }
                ?>
 >
							<label class="gfield_label"><?php 
                echo $label_subtotal;
                ?>
</label>
							<div class="ginput_container">
								<span class="formattedBasePrice ginput_total"></span>
							</div>
						</li>
						<li class="gfield" <?php 
                if ($disable_label_options == 'yes') {
                    echo 'style="display:none;"';
                }
                ?>
 >
							<label class="gfield_label"><?php 
                echo $label_options;
                ?>
</label>
							<div class="ginput_container">
								<span class="formattedVariationTotal ginput_total"></span>
							</div>
						</li>
						<li class="gfield" <?php 
                if ($disable_label_total == 'yes') {
                    echo 'style="display:none;"';
                }
                ?>
 >
							<label class="gfield_label"><?php 
                echo $label_total;
                ?>
</label>
							<div class="ginput_container">
								<span class="formattedTotalPrice ginput_total"></span>
							</div>
						</li>
					</ul>
				</div>
				<style>
					.single_variation .price {
						display:none !important;
					}
				</style>
			<?php 
            }
            ?>
			<style>
				.hidden-total {
					display:none !important;
				}
			</style>



			<?php 
            echo '</div>';
        }
    }
 /**
  * Calculate the item price based on the given measurements
  *
  * @since 3.1.3
  * @param WC_Product $product the product
  * @param float $measurement_needed_value the total measurement needed
  * @param string $measurement_needed_value_unit the unit of $measurement_needed_value
  * @param bool $round Optional. If true the returned price will be rounded to two decimal places. Default true.
  * @return float the calculated price
  */
 public static function calculate_price($product, $measurement_needed_value, $measurement_needed_value_unit, $round = true)
 {
     $price = $product->get_price();
     // get the parent product if there is one
     $_product = 'WC_Product_Variation' == get_class($product) ? $product->parent : $product;
     if (self::pricing_calculator_enabled($_product)) {
         $settings = new WC_Price_Calculator_Settings($_product);
         $measurement_needed = new WC_Price_Calculator_Measurement($measurement_needed_value_unit, (double) $measurement_needed_value);
         // if this calculator uses pricing rules, retrieve the price based on the product measurements
         if ($settings->pricing_rules_enabled()) {
             $product->price = $settings->get_pricing_rules_price($measurement_needed);
         }
         // calculate the price
         $price = $product->get_price() * $measurement_needed->get_value($settings->get_pricing_unit());
         // is there a minimum price to use?
         if ($product->wc_measurement_price_calculator_min_price > $price) {
             $price = $product->wc_measurement_price_calculator_min_price;
         }
     }
     if ($round) {
         $price = round($price, absint(get_option('woocommerce_price_num_decimals', 2)));
     }
     // return the final 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)
 {
     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());
 }
Ejemplo n.º 30
0
 /**
  * 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);
 }