Sale prices affect from: price now. Closes #44.

This commit is contained in:
Mike Jolley 2011-10-04 16:53:11 +01:00
parent dd48365a24
commit d05722a523
2 changed files with 12 additions and 9 deletions

View File

@ -634,21 +634,22 @@ function process_product_meta_variable( $post_id ) {
// Update parent if variable so price sorting works and stays in sync with the cheapest child
$post_parent = $post_id;
$children_by_price = get_posts( array(
$children = get_posts( array(
'post_parent' => $post_parent,
'orderby' => 'meta_value_num',
'order' => 'asc',
'meta_key' => 'price',
'posts_per_page' => 1,
'posts_per_page'=> -1,
'post_type' => 'product_variation',
'fields' => 'ids'
));
if ($children_by_price) :
foreach ($children_by_price as $child) :
$lowest_price = '';
if ($children) :
foreach ($children as $child) :
$child_price = get_post_meta($child, 'price', true);
update_post_meta( $post_parent, 'price', $child_price );
$child_sale_price = get_post_meta($child, 'sale_price', true);
if (!is_numeric($lowest_price) || $child_price<$lowest_price) $lowest_price = $child_price;
if (!empty($child_sale_price) && $child_sale_price<$lowest_price) $lowest_price = $child_sale_price;
endforeach;
endif;
update_post_meta( $post_parent, 'price', $lowest_price );
}
add_action('woocommerce_process_product_meta_variable', 'process_product_meta_variable');

View File

@ -202,7 +202,9 @@ class woocommerce_paypal extends woocommerce_payment_gateway {
$item_name = $item['name'];
if (isset($item['item_meta'])) :
$item_name .= ' ('.woocommerce_get_formatted_variation( $item['item_meta'], true ).')';
if ($meta = woocommerce_get_formatted_variation( $item['item_meta'], true )) :
$item_name .= ' ('.$meta.')';
endif;
endif;
$paypal_args['item_name_'.$item_loop] = $item_name;