本文整理汇总了PHP中WC_Product::get_price方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product::get_price方法的具体用法?PHP WC_Product::get_price怎么用?PHP WC_Product::get_price使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Product
的用法示例。
在下文中一共展示了WC_Product::get_price方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_product_data
/**
* 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());
}
示例2: get_product_display_price
/**
* 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;
}
}
示例3: woocs_product
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: get_composite_price_excluding_tax
/**
* 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;
}
示例5:
/**
* 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());
}
}
示例6: get_product_subtotal
/**
* 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);
}
示例7: vc_gitem_template_attribute_woocommerce_product
/**
* 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) : '';
}
示例8: hocwp_wc_get_product_price
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();
}
示例9: sv_wc_csv_export_order_line_item_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;
}
示例10: woocommerce_gravityforms_get_updated_price
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;
}
示例11: API
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);
}
}
}
}
示例12: get_ticket
/**
* 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);
}
示例13:
?>
</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>
示例14: get_composited_product_price
/**
* 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;
}
示例15: get_ticket
/**
* 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;
}