public function widget($args, $instance) { global $wpdb; $prices = $wpdb->get_row('SELECT COUNT(DISTINCT meta_value) AS count, MAX(meta_value) AS max, MIN(meta_value) AS min FROM ' . $wpdb->postmeta . ' AS m INNER JOIN ' . $wpdb->posts . ' ON m.post_id = ID WHERE meta_key = "_wpsc_price" AND meta_value > 0'); if (empty($prices->count)) { return; } $prices->min = round($prices->min); $prices->max = round($prices->max); $range_count = $prices->count > 5 ? 6 : $prices->count; $diff = ($prices->max - $prices->min) / $range_count; $instance = wp_parse_args($instance, $this->defaults); $title = apply_filters('widget_title', $instance['title']); if ($range_count == 1 || $prices->min == $prices->max) { return; } extract($args); echo $before_widget; if (!empty($title)) { echo $before_title . $title . $after_title; } echo '<ul>'; /** %1$s: min price, %2$s: max price **/ $text = _x('From %1$s to %2$s', 'price range widget', 'wpsc'); $range_max = $prices->min - 0.01; $i = 0; while ($range_max <= $prices->max) { $range_min = $range_max + 0.01; $range_max = $range_min + round($diff) - 0.01; $href = wpsc_get_store_url() . $range_min . '/' . $range_max; echo '<li>'; if ($i === 0) { echo '<a href="' . esc_url($href) . '">' . sprintf(__('Under %s', 'price range widget', 'wpsc'), wpsc_format_currency($range_max)) . '</a>'; } elseif ($range_max >= $prices->max) { echo '<a href="' . esc_url($href) . '">' . sprintf(__('Over %s', 'price range widget', 'wpsc'), wpsc_format_currency($range_min)) . '</a>'; } else { echo '<a href="' . esc_url($href) . '">' . sprintf($text, wpsc_format_currency($range_min), wpsc_format_currency($range_max)) . '</a>'; } echo '</li>'; $i++; } echo '</ul>'; echo $after_widget; }
function wpsc_get_product_you_save($product_id = null, $format = false, $from_text = true) { if (empty($product_id)) { $product_id = wpsc_get_product_id(); } if (!$format) { /* translators: %1$s: saving amount, %2$s: saving percent */ $format = _x('%1$s (%2$s)', 'product saving format', 'wpsc'); } $product = WPSC_Product::get_instance($product_id); $saving = wpsc_format_currency($product->saving); $saving_percent = sprintf(_x('%1$s%%', 'product saving percent', 'wpsc'), $product->saving_percent); $saving_text = sprintf($format, $saving, $saving_percent); if ($from_text && $product->has_various_savings) { $saving_text = _wpsc_get_from_text($saving_text); } return apply_filters('wpsc_get_product_you_save', $saving_text, $product_id, $format, $from_text); }
protected function column_item_total($item) { echo wpsc_format_currency($item->unit_price * $item->quantity); }
protected function column_total($item) { echo esc_html(wpsc_format_currency($item->totalprice)); }
<tr <?php $this->show_total_style(); ?> class="wpsc-cart-aggregate wpsc-cart-total-row"> <th scope="row" colspan="<?php echo count($this->columns) - 1; ?> "> <?php esc_html_e('Total:', 'wpsc'); ?> <br /> </th> <td> <?php echo esc_html(wpsc_format_currency($this->get_total_price())); ?> </td> </tr> <?php $this->tfoot_append(); ?> </tfoot> <tbody> <?php $this->display_rows(); ?> </tbody> </table> <!-- WP eCommerce Checkout Table Ends -->
function _wpsc_convert_checkout_shipping_form_args($args) { global $wpsc_shipping_modules; $calculator = WPSC_Shipping_Calculator::get_instance(); $submitted_value = wpsc_submitted_value('wpsc_shipping_option'); $active_shipping_id = $calculator->active_shipping_id; foreach ($calculator->sorted_quotes as $module_name => $quotes) { $radios = array('type' => 'radios', 'title' => $wpsc_shipping_modules[$module_name]->name, 'options' => array(), 'name' => 'wpsc_shipping_option'); foreach ($quotes as $option => $cost) { $id = $calculator->ids[$module_name][$option]; $checked = empty($submitted_value) ? $active_shipping_id == $id : $submitted_value == $id; $radios['options'][] = array('title' => $option, 'value' => $id, 'description' => wpsc_format_currency($cost), 'checked' => $checked); } $args['fields'][] = $radios; } // automatically select the cheapest option by default if (empty($active_shipping_id) && empty($submitted_value)) { $args['fields'][0]['options'][0]['checked'] = true; } return $args; }
/** * This seems...unfinished. Need to investigate usage. * * @todo Investigate intended usage, as this appears unfinished. * @param string $format [description] * @return [type] [description] */ public function get_you_save($format = '%1$d (%2$d)') { $diffs = array(); $diff_percents = array(); foreach ($this->prices as $item) { if ($item->sale_price) { $diff = (double) $item->price - (double) $item->sale_price; $diffs[] = $diff; $diff_percent[] = $diff / $item->price * 100; } } sort($diffs); sort($diff_percents); switch ($format) { case 'number': $output = (double) $diffs[0]; break; case 'percentage': case 'percent': $output = (double) round($diff_percents[0]); break; default: $output = sprintf($format, wpsc_format_currency($diffs[0]), $diff_percents[0]); } $first = $diff[0]; $count = count($diff); $last = $diff[$count - 1]; }