Merge pull request #703 from pixeltrix/add-variation-sale-pricing

Add previous price to on-sale variable product
This commit is contained in:
Mike Jolley 2012-02-26 04:47:36 -08:00
commit 9b349a3b91
2 changed files with 62 additions and 18 deletions

View File

@ -722,33 +722,37 @@ function process_product_meta_variable( $post_id ) {
'fields' => 'ids' 'fields' => 'ids'
)); ));
$lowest_price = ''; $lowest_price = '';
$lowest_regular_price = '';
$lowest_sale_price = '';
$highest_price = ''; $highest_price = '';
$highest_regular_price = '';
$highest_sale_price = '';
if ($children) : if ($children) :
foreach ($children as $child) : foreach ($children as $child) :
$child_price = get_post_meta($child, '_price', true); $child_price = get_post_meta($child, '_price', true);
$child_sale_price = get_post_meta($child, '_sale_price', true); $child_sale_price = get_post_meta($child, '_sale_price', true);
// Low price // Low price
if (!is_numeric($lowest_price) || $child_price<$lowest_price) $lowest_price = $child_price; if (!is_numeric($lowest_regular_price) || $child_price < $lowest_regular_price) $lowest_regular_price = $child_price;
if (!empty($child_sale_price) && $child_sale_price<$lowest_price) $lowest_price = $child_sale_price; if (!empty($child_sale_price) && (!is_numeric($lowest_sale_price) || $child_sale_price < $lowest_sale_price)) $lowest_sale_price = $child_sale_price;
// High price // High price
if (!empty($child_sale_price)) : if (!is_numeric($highest_regular_price) || @child_price > $highest_regular_price) $highest_regular_price = $child_price;
if ($child_sale_price>$highest_price) : if (!empty($child_sale_price) && (!is_numeric($highest_sale_price) || $child_sale_price > $highest_sale_price)) $highest_sale_price = $child_sale_price;
$highest_price = $child_sale_price;
endif;
else :
if ($child_price>$highest_price) :
$highest_price = $child_price;
endif;
endif;
endforeach; endforeach;
$lowest_price = empty($lowest_sale_price) ? $lowest_regular_price : $lowest_sale_price;
$highest_price = empty($highest_sale_price) ? $highest_regular_price : $highest_sale_price;
endif; endif;
update_post_meta( $post_parent, '_price', $lowest_price ); update_post_meta( $post_parent, '_price', $lowest_price );
update_post_meta( $post_parent, '_min_variation_price', $lowest_price ); update_post_meta( $post_parent, '_min_variation_price', $lowest_price );
update_post_meta( $post_parent, '_max_variation_price', $highest_price ); update_post_meta( $post_parent, '_max_variation_price', $highest_price );
update_post_meta( $post_parent, '_min_variation_regular_price', $lowest_regular_price );
update_post_meta( $post_parent, '_max_variation_regular_price', $highest_regular_price );
update_post_meta( $post_parent, '_min_variation_sale_price', $lowest_sale_price );
update_post_meta( $post_parent, '_max_variation_sale_price', $highest_sale_price );
// Update default attribute options setting // Update default attribute options setting
$default_attributes = array(); $default_attributes = array();

View File

@ -42,6 +42,10 @@ class WC_Product {
var $sale_price_dates_to; var $sale_price_dates_to;
var $min_variation_price; var $min_variation_price;
var $max_variation_price; var $max_variation_price;
var $min_variation_regular_price;
var $max_variation_regular_price;
var $min_variation_sale_price;
var $max_variation_sale_price;
var $featured; var $featured;
var $shipping_class; var $shipping_class;
var $dimensions; var $dimensions;
@ -84,6 +88,10 @@ class WC_Product {
'sale_price_dates_to' => '', 'sale_price_dates_to' => '',
'min_variation_price' => '', 'min_variation_price' => '',
'max_variation_price' => '', 'max_variation_price' => '',
'min_variation_regular_price' => '',
'max_variation_regular_price' => '',
'min_variation_sale_price' => '',
'max_variation_sale_price' => '',
'featured' => 'no' 'featured' => 'no'
); );
@ -536,13 +544,45 @@ class WC_Product {
$price = apply_filters('woocommerce_grouped_price_html', $price, $this); $price = apply_filters('woocommerce_grouped_price_html', $price, $this);
elseif ($this->is_type('variable')) : elseif ($this->is_type('variable')) :
if ($this->price > 0) :
if ( !$this->min_variation_price || $this->min_variation_price !== $this->max_variation_price ) $price .= '<span class="from">' . _x('From:', 'min_price', 'woocommerce') . ' </span>'; if ($this->is_on_sale() && isset($this->min_variation_price)) :
$price .= woocommerce_price($this->get_price()); if ( !$this->min_variation_price || $this->min_variation_price !== $this->max_variation_price ) $price .= '<span class="from">' . _x('From:', 'min_price', 'woocommerce') . ' </span>';
$price .= '<del>'.woocommerce_price( $this->min_variation_regular_price ).'</del> <ins>'.woocommerce_price($this->get_price()).'</ins>';
$price = apply_filters('woocommerce_variable_price_html', $price, $this);
$price = apply_filters('woocommerce_variable_sale_price_html', $price, $this);
else :
if ( !$this->min_variation_price || $this->min_variation_price !== $this->max_variation_price ) $price .= '<span class="from">' . _x('From:', 'min_price', 'woocommerce') . ' </span>';
$price .= woocommerce_price($this->get_price());
$price = apply_filters('woocommerce_variable_price_html', $price, $this);
endif;
elseif ($this->price === '' ) :
$price = apply_filters('woocommerce_variable_empty_price_html', '', $this);
elseif ($this->price == 0 ) :
if ($this->is_on_sale() && isset($this->min_variation_regular_price)) :
if ( !$this->min_variation_price || $this->min_variation_price !== $this->max_variation_price ) $price .= '<span class="from">' . _x('From:', 'min_price', 'woocommerce') . ' </span>';
$price .= '<del>'.woocommerce_price( $this->min_variation_regular_price ).'</del> <ins>'.__('Free!', 'woocommerce').'</ins>';
$price = apply_filters('woocommerce_variable_free_sale_price_html', $price, $this);
else :
if ( !$this->min_variation_price || $this->min_variation_price !== $this->max_variation_price ) $price .= '<span class="from">' . _x('From:', 'min_price', 'woocommerce') . ' </span>';
$price = __('Free!', 'woocommerce');
$price = apply_filters('woocommerce_variable_free_price_html', $price, $this);
endif;
endif;
else : else :
if ($this->price > 0) : if ($this->price > 0) :
if ($this->is_on_sale() && isset($this->regular_price)) : if ($this->is_on_sale() && isset($this->regular_price)) :