本文整理汇总了PHP中wpsc_calculate_price函数的典型用法代码示例。如果您正苦于以下问题:PHP wpsc_calculate_price函数的具体用法?PHP wpsc_calculate_price怎么用?PHP wpsc_calculate_price使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpsc_calculate_price函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: wpsc_you_save
function wpsc_you_save($args = null)
{
$defaults = array('product_id' => false, 'type' => 'percentage', 'variations' => false);
$args = wp_parse_args($args, $defaults);
extract($args, EXTR_SKIP);
global $wpdb;
if (!$product_id) {
if (function_exists('wpsc_the_product_id')) {
//select the variation ID with lowest price
$product_id = $wpdb->get_var('SELECT `posts`.`id` FROM ' . $wpdb->posts . ' `posts` JOIN ' . $wpdb->postmeta . ' `postmeta` ON `posts`.`id` = `postmeta`.`post_id` WHERE `posts`.`post_parent` = ' . wpsc_the_product_id() . ' AND `posts`.`post_type` = "wpsc-product" AND `posts`.`post_status` = "inherit" AND `postmeta`.`meta_key`="_wpsc_price" ORDER BY (`postmeta`.`meta_value`)+0 ASC LIMIT 1');
if (!$product_id) {
$product_id = wpsc_the_product_id();
}
}
}
if (!$product_id) {
return 0;
}
$regular_price = wpsc_calculate_price($product_id, $variations, false);
$sale_price = wpsc_calculate_price($product_id, $variations, true);
switch ($type) {
case "amount":
return $regular_price - $sale_price;
break;
default:
if ($regular_price == 0) {
return 0;
} else {
return number_format(($regular_price - $sale_price) / $regular_price * 100, 2);
}
}
}
开发者ID:AngryBird3,项目名称:WP-e-Commerce,代码行数:32,代码来源:template-tags.php
示例2: wpsc_update_product_price
/**
* update_product_page_price function, used through ajax with variations
* No parameters, returns nothing
*/
function wpsc_update_product_price()
{
global $wpdb, $wpsc_cart;
$from = '';
$change_price = true;
foreach ((array) $_POST['variation'] as $variation) {
if (is_numeric($variation)) {
$variations[] = (int) $variation;
}
if ($variation == 0) {
$from = ' from ';
$from = apply_filters('wpsc_product_variation_text', $from);
$change_price = false;
}
}
do_action('wpsc_update_variation_product', (int) $_POST['product_id'], $variations);
$pm = $_POST['pm'];
$stock = wpsc_check_variation_stock_availability((int) $_POST['product_id'], $variations);
if (is_numeric($stock) && $stock == 0) {
echo "product_msg=\"" . __('Sorry, but this variation is out of stock.', 'wpsc') . "\";\n";
echo "variation_msg=\"" . __('Produto não disponível', 'wpsc') . "\";\n";
echo "variation_status= false \n";
} else {
echo "variation_msg=\"" . __('Product in stock', 'wpsc') . "\";\n";
echo "variation_status= true \n";
}
echo "product_id=" . (int) $_POST['product_id'] . ";\n";
if ($change_price) {
echo "old_price=\"" . wpsc_currency_display(wpsc_calculate_price((int) $_POST['product_id'], $variations, false), array('display_as_html' => false)) . "\";\n";
echo "numeric_old_price=\"" . number_format(wpsc_calculate_price((int) $_POST['product_id'], $variations, false)) . "\";\n";
echo "you_save=\"" . wpsc_currency_display(wpsc_you_save(array('product_id' => (int) $_POST['product_id'], 'type' => 'amount', 'variations' => $variations)), array('display_as_html' => false)) . "! (" . wpsc_you_save(array('product_id' => (int) $_POST['product_id'], 'variations' => $variations)) . "%)\";\n";
echo "price=\"" . $from . wpsc_currency_display(wpsc_calculate_price((int) $_POST['product_id'], $variations, true), array('display_as_html' => false)) . "\";\n";
echo "numeric_price=\"" . number_format(wpsc_calculate_price((int) $_POST['product_id'], $variations, true)) . "\";\n";
}
exit;
}
开发者ID:hornet9,项目名称:Morato,代码行数:40,代码来源:ajax.functions.php
示例3: wpsc_the_product_id
<?php
if (wpsc_product_is_donation()) {
?>
<label for="donation_price_<?php
echo wpsc_the_product_id();
?>
"><?php
_e('Donation', 'wpsc');
?>
: </label>
<input type="text" id="donation_price_<?php
echo wpsc_the_product_id();
?>
" name="donation_price" value="<?php
echo wpsc_calculate_price(wpsc_the_product_id());
?>
" size="6" />
<?php
} else {
?>
<?php
wpsc_the_product_price_display();
?>
<!-- multi currency code -->
<?php
if (wpsc_product_has_multicurrency()) {
?>
<?php
echo wpsc_display_product_multicurrency();
?>
开发者ID:samtripp,项目名称:emporium-theme,代码行数:30,代码来源:wpsc-single_product.php
示例4: wpsc_generate_product_feed
function wpsc_generate_product_feed()
{
global $wpdb, $wp_query, $post;
// Don't cache feed under WP Super-Cache
define('DONOTCACHEPAGE', TRUE);
$siteurl = get_option('siteurl');
// Allow limiting
if (isset($_GET['limit']) && is_numeric($_GET['limit'])) {
$limit = "LIMIT " . $_GET['limit'] . "";
} else {
$limit = '';
}
$selected_category = '';
$selected_product = '';
if (isset($_GET['product_id']) && is_numeric($_GET['product_id'])) {
$args[] = array('post__in' => $_GET['product_id']);
} elseif (isset($_GET['category_id']) && is_numeric($_GET['category_id'])) {
$args[] = array('cat' => $_GET['category_id']);
}
$args['post_type'] = 'wpsc-product';
$args['posts_per_page'] = 999;
$products = query_posts($args);
$self = get_option('siteurl') . "/index.php?rss=true&action=product_list{$selected_category}{$selected_product}";
header("Content-Type: application/xml; charset=UTF-8");
header('Content-Disposition: inline; filename="E-Commerce_Product_List.rss"');
$output = "<?xml version='1.0' encoding='UTF-8' ?>\n\r";
$output .= "<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'";
$google_checkout_note = FALSE;
if ($_GET['xmlformat'] == 'google') {
$output .= ' xmlns:g="http://base.google.com/ns/1.0"';
// Is Google Checkout available as a payment gateway
$selected_gateways = get_option('custom_gateway_options');
if (in_array('google', $selected_gateways)) {
$google_checkout_note = TRUE;
}
} else {
$output .= ' xmlns:product="http://www.buy.com/rss/module/productV2/"';
}
$output .= ">\n\r";
$output .= " <channel>\n\r";
$output .= " <title><![CDATA[" . get_option('blogname') . " Products]]></title>\n\r";
$output .= " <link>" . get_option('siteurl') . "/wp-admin/admin.php?page=" . WPSC_DIR_NAME . "/display-log.php</link>\n\r";
$output .= " <description>This is the WP e-Commerce Product List RSS feed</description>\n\r";
$output .= " <generator>WP e-Commerce Plugin</generator>\n\r";
$output .= " <atom:link href='{$self}' rel='self' type='application/rss+xml' />\n\r";
foreach ($products as $post) {
setup_postdata($post);
$purchase_link = wpsc_product_url($post->ID);
$output .= " <item>\n\r";
if ($google_checkout_note) {
$output .= " <g:payment_notes>Google Checkout</g:payment_notes>\n\r";
}
$output .= " <title><![CDATA[" . get_the_title() . "]]></title>\n\r";
$output .= " <link>{$purchase_link}</link>\n\r";
$output .= " <description><![CDATA[" . get_the_content() . "]]></description>\n\r";
$output .= " <pubDate>" . $post->post_modified_gmt . "</pubDate>\n\r";
$output .= " <guid>{$purchase_link}</guid>\n\r";
$image_link = FALSE;
if (has_post_thumbnail($post->ID)) {
$post_thumbnail_id = get_post_thumbnail_id($post->ID);
$src = wp_get_attachment_image_src($post_thumbnail_id, 'large');
$image_link = $src[0];
}
if ($image_link !== FALSE) {
if ($_GET['xmlformat'] == 'google') {
$output .= " <g:image_link>{$image_link}</g:image_link>\n\r";
} else {
$output .= " <enclosure url='{$image_link}' />\n\r";
}
}
$price = wpsc_calculate_price($post->ID);
$children = get_children(array('post_parent' => $post->ID, 'post_type' => 'wpsc-product'));
foreach ($children as $child) {
$child_price = wpsc_calculate_price($child->ID);
if ($price == 0 && $child_price > 0) {
$price = $child_price;
} else {
if ($child_price > 0 && $child_price < $price) {
$price = $child_price;
}
}
}
if ($_GET['xmlformat'] == 'google') {
$output .= " <g:price>" . $price . "</g:price>\n\r";
$product_meta = get_post_meta($post->ID, '_wpsc_product_metadata', true);
foreach (array_keys($product_meta) as $meta_key) {
if (stripos($meta_key, 'g:') === 0) {
$google_elements[$meta_key] = $product_meta[$meta_key];
}
}
$google_elements = apply_filters('wpsc_google_elements', array('product_id' => $product['id'], 'elements' => $google_elements));
$google_elements = $google_elements['elements'];
$done_condition = FALSE;
if (count($google_elements)) {
foreach ($google_elements as $gelement) {
$output .= " <" . $gelement['meta_key'] . ">";
$output .= "<![CDATA[" . $gelement['meta_value'] . "]]>";
$output .= "</" . $gelement['meta_key'] . ">\n\r";
if ($gelement['meta_key'] == 'g:condition') {
$done_condition = TRUE;
//.........这里部分代码省略.........
开发者ID:hornet9,项目名称:Morato,代码行数:101,代码来源:productfeed.php
示例5: wpsc_update_product_price
/**
* update_product_page_price function, used through ajax with variations
* No parameters, returns nothing
*/
function wpsc_update_product_price()
{
$from = '';
$change_price = true;
$product_id = (int) $_POST['product_id'];
$variations = array();
$response = array('product_id' => $product_id, 'variation_found' => false);
if (!empty($_POST['variation'])) {
foreach ($_POST['variation'] as $variation) {
if (is_numeric($variation)) {
$variations[] = (int) $variation;
}
}
do_action('wpsc_update_variation_product', $product_id, $variations);
$stock = wpsc_check_variation_stock_availability($product_id, $variations);
if ($stock !== false) {
$response['variation_found'] = true;
if ($stock === 0) {
$response += array('product_msg' => __('Sorry, but this variation is out of stock.', 'wpsc'), 'variation_msg' => __('Variation not in stock', 'wpsc'), 'stock_available' => false);
} else {
$response += array('variation_msg' => __('Product in stock', 'wpsc'), 'stock_available' => true);
}
if ($change_price) {
$old_price = wpsc_calculate_price($product_id, $variations, false);
$you_save_amount = wpsc_you_save(array('product_id' => $product_id, 'type' => 'amount', 'variations' => $variations));
$you_save_percentage = wpsc_you_save(array('product_id' => $product_id, 'variations' => $variations));
$price = wpsc_calculate_price($product_id, $variations, true);
$response += array('old_price' => wpsc_currency_display($old_price, array('display_as_html' => false)), 'numeric_old_price' => (double) number_format($old_price), 'you_save' => wpsc_currency_display($you_save_amount, array('display_as_html' => false)) . "! (" . $you_save_percentage . "%)", 'price' => $from . wpsc_currency_display($price, array('display_as_html' => false)), 'numeric_price' => (double) number_format($price));
}
}
}
echo json_encode($response);
exit;
}
开发者ID:arturo-mayorga,项目名称:am_com,代码行数:38,代码来源:ajax.functions.php
示例6: _e
<?php
if (wpsc_product_is_donation()) {
?>
<label for="donation_price_<?php
echo $product_id;
?>
"><?php
_e('Donation', ETHEME_DOMAIN);
?>
: </label>
<input type="text" id="donation_price_<?php
echo $product_id;
?>
" name="donation_price"
value="<?php
echo wpsc_calculate_price($product_id);
?>
" size="6"/>
<?php
}
?>
<input type="hidden" value="add_to_cart" name="wpsc_ajax_action"/>
<input type="hidden" value="<?php
echo $product_id;
?>
" name="product_id"/>
<hr>
<div class="addto-container">
开发者ID:Nguyenkain,项目名称:hanghieusales,代码行数:31,代码来源:wpsc-single_product.php
示例7: wpsc_you_save
function wpsc_you_save($args = null)
{
$defaults = array('product_id' => false, 'type' => "percentage", 'variations' => false);
$args = wp_parse_args($args, $defaults);
extract($args, EXTR_SKIP);
global $wpdb;
if (!$product_id) {
if (function_exists('wpsc_the_product_id')) {
//select the variation ID with lowest price
$product_id = $wpdb->get_var('SELECT `posts`.`id` FROM ' . $wpdb->posts . ' `posts` JOIN ' . $wpdb->postmeta . ' `postmeta` ON `posts`.`id` = `postmeta`.`post_id` WHERE `posts`.`post_parent` = ' . wpsc_the_product_id() . ' AND `posts`.`post_type` = "wpsc-product" AND `posts`.`post_status` = "inherit" AND `postmeta`.`meta_key`="_wpsc_price" ORDER BY (`postmeta`.`meta_value`)+0 ASC LIMIT 1');
if (!$product_id) {
$product_id = wpsc_the_product_id();
}
}
}
if (!$product_id) {
return 0;
}
if ($variations) {
$sale_price = wpsc_calculate_price((int) $_POST['product_id'], $variations, true);
} else {
$sale_price = get_product_meta($product_id, 'special_price', true);
}
//if sale price is zero, false, or anything similar - return false
if (!$sale_price) {
return 0;
}
if ($variations) {
$regular_price = wpsc_calculate_price((int) $_POST['product_id'], $variations, false);
} else {
$regular_price = get_product_meta($product_id, 'price', true);
}
//if actual price is zero, false, or something similar, or is less than sale price - return false
if (!$regular_price || !($sale_price < $regular_price)) {
return 0;
}
switch ($type) {
case "amount":
return $regular_price - $sale_price;
break;
default:
if (number_format(($regular_price - $sale_price) / $regular_price * 100, 2) == 100) {
return 99.98999999999999;
} else {
return number_format(($regular_price - $sale_price) / $regular_price * 100, 2);
}
}
}
开发者ID:hornet9,项目名称:Morato,代码行数:48,代码来源:product-template.php
示例8: wpsc_generate_product_feed
function wpsc_generate_product_feed()
{
global $wpdb, $wp_query, $post;
set_time_limit(0);
// Don't build up a huge posts cache for the whole store - http://code.google.com/p/wp-e-commerce/issues/detail?id=885
// WP 3.3+ only
if (function_exists('wp_suspend_cache_addition')) {
wp_suspend_cache_addition(true);
}
$chunk_size = apply_filters('wpsc_productfeed_chunk_size', 50);
// Don't cache feed under WP Super-Cache
define('DONOTCACHEPAGE', TRUE);
$selected_category = '';
$selected_product = '';
$args = array('post_type' => 'wpsc-product', 'numberposts' => $chunk_size, 'offset' => 0, 'cache_results' => false);
$args = apply_filters('wpsc_productfeed_query_args', $args);
$self = site_url("/index.php?rss=true&action=product_list{$selected_category}{$selected_product}");
header("Content-Type: application/xml; charset=UTF-8");
header('Content-Disposition: inline; filename="E-Commerce_Product_List.rss"');
echo "<?xml version='1.0' encoding='UTF-8' ?>\n\r";
echo "<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'";
$google_checkout_note = false;
if ($_GET['xmlformat'] == 'google') {
echo ' xmlns:g="http://base.google.com/ns/1.0"';
// Is Google Checkout available as a payment gateway
$selected_gateways = get_option('custom_gateway_options');
if (in_array('google', $selected_gateways)) {
$google_checkout_note = true;
}
} else {
echo ' xmlns:product="http://www.buy.com/rss/module/productV2/"';
}
echo ">\n\r";
echo " <channel>\n\r";
echo " <title><![CDATA[" . get_option('blogname') . " Products]]></title>\n\r";
echo " <link>" . get_option('siteurl') . "/wp-admin/admin.php?page=" . WPSC_DIR_NAME . "/display-log.php</link>\n\r";
echo " <description>This is the WP e-Commerce Product List RSS feed</description>\n\r";
echo " <generator>WP e-Commerce Plugin</generator>\n\r";
echo " <atom:link href='{$self}' rel='self' type='application/rss+xml' />\n\r";
$products = get_posts($args);
while (count($products)) {
foreach ($products as $post) {
setup_postdata($post);
$purchase_link = wpsc_product_url($post->ID);
echo " <item>\n\r";
if ($google_checkout_note) {
echo " <g:payment_notes>Google Checkout</g:payment_notes>\n\r";
}
echo " <title><![CDATA[" . get_the_title() . "]]></title>\n\r";
echo " <link>{$purchase_link}</link>\n\r";
echo " <description><![CDATA[" . apply_filters('the_content', get_the_content()) . "]]></description>\n\r";
echo " <pubDate>" . $post->post_modified_gmt . "</pubDate>\n\r";
echo " <guid>{$purchase_link}</guid>\n\r";
$image_link = wpsc_the_product_thumbnail();
if ($image_link !== FALSE) {
if ($_GET['xmlformat'] == 'google') {
echo " <g:image_link>{$image_link}</g:image_link>\n\r";
} else {
echo " <enclosure url='{$image_link}' />\n\r";
}
}
$price = wpsc_calculate_price($post->ID);
$currargs = array('display_currency_symbol' => false, 'display_decimal_point' => true, 'display_currency_code' => false, 'display_as_html' => false);
$price = wpsc_currency_display($price, $currargs);
$children = get_children(array('post_parent' => $post->ID, 'post_type' => 'wpsc-product'));
foreach ($children as $child) {
$child_price = wpsc_calculate_price($child->ID);
if ($price == 0 && $child_price > 0) {
$price = $child_price;
} else {
if ($child_price > 0 && $child_price < $price) {
$price = $child_price;
}
}
}
if ($_GET['xmlformat'] == 'google') {
echo " <g:price>" . $price . "</g:price>\n\r";
$google_elements = array();
$product_meta = get_post_custom($post->ID);
if (is_array($product_meta)) {
foreach ($product_meta as $meta_key => $meta_value) {
if (stripos($meta_key, 'g:') === 0) {
$google_elements[$meta_key] = $meta_value;
}
}
}
$google_elements = apply_filters('wpsc_google_elements', array('product_id' => $post->ID, 'elements' => $google_elements));
$google_elements = $google_elements['elements'];
$done_condition = FALSE;
$done_availability = FALSE;
$done_weight = FALSE;
if (count($google_elements)) {
foreach ($google_elements as $element_name => $element_values) {
foreach ($element_values as $element_value) {
echo " <" . $element_name . ">";
echo "<![CDATA[" . $element_value . "]]>";
echo "</" . $element_name . ">\n\r";
}
if ($element_name == 'g:shipping_weight') {
$done_weight = TRUE;
//.........这里部分代码省略.........
开发者ID:arturo-mayorga,项目名称:am_com,代码行数:101,代码来源:productfeed.php
示例9: wpsc_specials
//.........这里部分代码省略.........
<img class="no-image" id="product_image_<?php
echo wpsc_the_product_id();
?>
" alt="No Image" title="<?php
echo wpsc_the_product_title();
?>
" src="<?php
echo WPSC_URL;
?>
/wpsc-theme/wpsc-images/noimage.png" width="<?php
esc_attr_e(get_option('product_image_width'));
?>
" height="<?php
esc_attr_e(get_option('product_image_height'));
?>
" />
</a>
<?php
}
?>
<?php
}
// close show thumbnails
?>
<br />
<span id="special_product_price_<?php
echo wpsc_the_product_id();
?>
">
<!-- price display -->
<?php
if (wpsc_have_variation_groups()) {
while (wpsc_have_variation_groups()) {
wpsc_the_variation_group();
?>
<?php
/** the variation HTML and loop */
?>
<?php
$variation_outputs = array();
?>
<?php
while (wpsc_have_variations()) {
wpsc_the_variation();
?>
<?php
$variation_outputs[] = '';
$variation_prices[] = wpsc_the_variation_price(true);
}
// Sort the variations into price order before outputting
$data[] = $variation_outputs;
$data[] = $variation_prices;
array_multisort($data[1], SORT_ASC, SORT_NUMERIC, $data[0], SORT_ASC, SORT_STRING);
?>
<?php
}
echo __('From', 'wpsc') . ' : ' . wpsc_currency_display($data[1][0]);
?>
<?php
} else {
?>
<?php
echo wpsc_currency_display(wpsc_calculate_price(wpsc_the_product_id(), null, true));
?>
<?php
}
?>
</span><br />
<strong><a class="wpsc_product_title" href="<?php
echo wpsc_product_url(wpsc_the_product_id(), false);
?>
"><?php
echo wpsc_the_product_title();
?>
</a></strong><br />
<?php
if ($show_description) {
?>
<div class="wpsc-special-description">
<?php
echo wpsc_the_product_description();
?>
</div>
<?php
}
// close show description
?>
<?php
}
}
list($wp_query, $special_products) = array($special_products, $wp_query);
// swap the wpsc_query object
wp_reset_query();
}
}
开发者ID:hornet9,项目名称:Morato,代码行数:101,代码来源:specials_widget.php
示例10: send_product
public function send_product()
{
if (wpsc_is_single_product()) {
$product = array();
while (wpsc_have_products()) {
wpsc_the_product();
$product_id = (int) wpsc_the_product_id();
$product['url'] = (string) wpsc_the_product_permalink();
$product['product_id'] = $product_id;
$product['name'] = (string) wpsc_the_product_title();
$product['image_url'] = (string) wpsc_the_product_image('', '', $product_id);
if (wpsc_product_has_variations($product_id)) {
$price = $this->get_lowest_product_variation_price($product_id);
} else {
$price = wpsc_calculate_price($product_id, false, true);
}
$product['price'] = $this->format_price($price);
if (wpsc_product_has_stock($product_id)) {
$product['stock'] = 1;
} else {
$product['stock'] = 0;
}
$product['categories'] = array();
$category_terms = wp_get_product_categories($product_id);
foreach ($category_terms as $category_term) {
$category_path = $category_term;
if (!empty($category_path)) {
$product['category_name'] = $category_term->name;
$product['category_id'] = $category_term->term_id;
}
}
if (wpsc_product_has_variations($product_id)) {
$list_price = $this->get_lowest_product_variation_price($product_id);
} else {
$list_price = wpsc_calculate_price($product_id, false, false);
}
$product['list_price'] = $this->format_price($list_price);
}
if (!empty($product)) {
$this->render('sendProduct', array('product' => $product));
}
}
}
开发者ID:retargeting,项目名称:WP-eCommerce,代码行数:43,代码来源:wpec-retargeting.php
注:本文中的wpsc_calculate_price函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论