Пример #1
0
function wpsc_the_product_price_display($args = array())
{
    if (empty($args['id'])) {
        $id = get_the_ID();
    } else {
        $id = (int) $args['id'];
    }
    $defaults = array('id' => $id, 'old_price_text' => __('Old Price: %s', 'wp-e-commerce'), 'price_text' => __('Price: %s', 'wp-e-commerce'), 'you_save_text' => __('You save: %s', 'wp-e-commerce'), 'old_price_class' => 'pricedisplay wpsc-product-old-price ' . $id, 'old_price_before' => '<p %s>', 'old_price_after' => '</p>', 'old_price_amount_id' => 'old_product_price_' . $id, 'old_price_amount_class' => 'oldprice', 'old_price_amount_before' => '<span class="%1$s" id="%2$s">', 'old_price_amount_after' => '</span>', 'price_amount_id' => 'product_price_' . $id, 'price_class' => 'pricedisplay wpsc-product-price ' . $id, 'price_before' => '<p %s>', 'price_after' => '</p>', 'price_amount_class' => 'currentprice pricedisplay ' . $id, 'price_amount_before' => '<span class="%1$s" id="%2$s">', 'price_amount_after' => '</span>', 'you_save_class' => 'pricedisplay wpsc-product-you-save product_' . $id, 'you_save_before' => '<p %s>', 'you_save_after' => '</p>', 'you_save_amount_id' => 'yousave_' . $id, 'you_save_amount_class' => 'yousave', 'you_save_amount_before' => '<span class="%1$s" id="%2$s">', 'you_save_amount_after' => '</span>', 'output_price' => true, 'output_old_price' => true, 'output_you_save' => true);
    $r = wp_parse_args($args, $defaults);
    /**
     * wpsc_the_product_price_display_args filter args for product price display
     *
     * Paramters used to format price display can be set globally using this filter
     *
     * @since 4.0
     *
     * @type array $args array of parameters used to format product price
     * @type int $product_id WPeC Product ID for the current product
     */
    $r = apply_filters('wpsc_the_product_price_display_args', $r, $id);
    extract($r);
    // if the product has no variations, these amounts are straight forward...
    $old_price = wpsc_product_normal_price($id);
    $current_price = wpsc_the_product_price(false, false, $id);
    $you_save = wpsc_you_save(array('type' => 'amount', 'product_id' => $id));
    $show_old_price = $show_you_save = wpsc_product_on_special($id);
    // Don't output old price HTML if not on sale.
    if (!wpsc_product_on_special($id)) {
        $output_old_price = $output_you_save = false;
    }
    // but if the product has variations and at least one of the variations is on special, we have
    // a few edge cases...
    if (wpsc_product_has_variations($id) && wpsc_product_on_special($id)) {
        // generally it doesn't make sense to display "you save" amount unless the user has selected
        // a specific variation
        $show_you_save = false;
        $old_price_number = wpsc_product_variation_price_from($id, array('only_normal_price' => true));
        $current_price_number = wpsc_product_variation_price_from($id);
        // if coincidentally, one of the variations are not on special, but its price is equal to
        // or lower than the lowest variation sale price, old price should be hidden, and current
        // price should reflect the "normal" price, not the sales price, to avoid confusion
        if ($old_price_number == $current_price_number) {
            $show_old_price = false;
            $current_price = wpsc_product_normal_price($id);
        }
    }
    // replace placeholders in arguments with correct values
    $old_price_class = apply_filters('wpsc_the_product_price_display_old_price_class', $old_price_class, $id);
    $old_price_amount_class = apply_filters('wpsc_the_product_price_display_old_price_amount_class', $old_price_amount_class, $id);
    $attributes = 'class="' . esc_attr($old_price_class) . '"';
    if (!$show_old_price) {
        $attributes .= ' style="display:none;"';
    }
    $old_price_before = sprintf($old_price_before, $attributes);
    $old_price_amount_before = sprintf($old_price_amount_before, esc_attr($old_price_amount_class), esc_attr($old_price_amount_id));
    $price_class = 'class="' . esc_attr(apply_filters('wpsc_the_product_price_display_price_class', esc_attr($price_class), $id)) . '"';
    $price_amount_class = apply_filters('wpsc_the_product_price_display_price_amount_class', esc_attr($price_amount_class), $id);
    $price_before = sprintf($price_before, $price_class);
    $price_amount_before = sprintf($price_amount_before, esc_attr($price_amount_class), esc_attr($price_amount_id));
    $you_save_class = apply_filters('wpsc_the_product_price_display_you_save_class', $you_save_class, $id);
    $you_save_amount_class = apply_filters('wpsc_the_product_price_display_you_save_amount_class', $you_save_amount_class, $id);
    $attributes = 'class="' . esc_attr($you_save_class) . '"';
    if (!$show_you_save) {
        $attributes .= ' style="display:none;"';
    }
    $you_save_before = sprintf($you_save_before, $attributes);
    $you_save_amount_before = sprintf($you_save_amount_before, esc_attr($you_save_amount_class), esc_attr($you_save_amount_id));
    $you_save = wpsc_currency_display($you_save);
    $old_price = $old_price_amount_before . $old_price . $old_price_amount_after;
    $current_price = $price_amount_before . $current_price . $price_amount_after;
    $you_save = $you_save_amount_before . $you_save . $you_save_amount_after;
    $old_price_text = sprintf($old_price_text, $old_price);
    $price_text = sprintf($price_text, $current_price);
    $you_save_text = sprintf($you_save_text, $you_save);
    if ($output_old_price) {
        echo $old_price_before . $old_price_text . $old_price_after . "\n";
    }
    if ($output_price) {
        echo $price_before . $price_text . $price_after . "\n";
    }
    if ($output_you_save) {
        echo $you_save_before . $you_save_text . $you_save_after . "\n";
    }
}
Пример #2
0
/**
 * 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&atilde;o dispon&iacute;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;
}
function vtprd_show_product_you_save($product_id = null)
{
    global $post, $vtprd_setup_options, $vtprd_info;
    //can only be executed when WPEC version less than 3.8.9
    if (!(version_compare(strval('3.8.9'), strval(WPSC_VERSION), '>') == 1)) {
        //'==1' = 2nd value is lower
        return;
    }
    $pct = vtprd_get_single_product_you_save_pct($product_id);
    $amt = $vtprd_info['product_session_info']['product_yousave_total_amt'];
    $amt = vtprd_format_money_element($amt);
    //CUSTOM function created by CUSTOMER
    if (function_exists('custom_show_single_product_you_save')) {
        custom_show_single_product_you_save($product_id, $pct, $amt);
        return;
    }
    if ($pct) {
        ?>
				<p class="pricedisplay product_<?php 
        echo wpsc_the_product_id();
        ?>
"><?php 
        _e('You save', 'wpsc');
        ?>
: <span class="yousave" id="yousave_<?php 
        echo wpsc_the_product_id();
        ?>
"><?php 
        echo $amt;
        ?>
! (<?php 
        echo $pct;
        ?>
%)</span></p>
			<?php 
    } else {
        //original code from wpsc-single_product.php
        ?>
      
        <?php 
        if (wpsc_product_on_special()) {
            ?>
					<p class="pricedisplay product_<?php 
            echo wpsc_the_product_id();
            ?>
"><?php 
            _e('You save', 'wpsc');
            ?>
: <span class="yousave" id="yousave_<?php 
            echo wpsc_the_product_id();
            ?>
"><?php 
            echo wpsc_currency_display(wpsc_you_save('type=amount'), array('html' => false));
            ?>
! (<?php 
            echo wpsc_you_save();
            ?>
%)</span></p>
				<?php 
        }
        ?>
      
      <?php 
    }
    return;
}
Пример #4
0
/**
 * 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;
}
        <span class="you-save product_<?php 
            echo $product_id;
            ?>
"><?php 
            _e('You save', ETHEME_DOMAIN);
            ?>
: <span
            class="price"
            id="yousave_<?php 
            echo $product_id;
            ?>
"><?php 
            echo wpsc_currency_display(wpsc_you_save('type=amount'), array('html' => false));
            ?>
            (<?php 
            echo wpsc_you_save();
            ?>
%)</span></span>

      <?php 
        }
        ?>
      <!-- multi currency code -->
      <?php 
        if (wpsc_product_has_multicurrency()) {
            ?>
        <?php 
            echo wpsc_display_product_multicurrency();
            ?>
      <?php 
        }