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 // Update parent if variable so price sorting works and stays in sync with the cheapest child
$post_parent = $post_id; $post_parent = $post_id;
$children_by_price = get_posts( array( $children = get_posts( array(
'post_parent' => $post_parent, 'post_parent' => $post_parent,
'orderby' => 'meta_value_num', 'posts_per_page'=> -1,
'order' => 'asc',
'meta_key' => 'price',
'posts_per_page' => 1,
'post_type' => 'product_variation', 'post_type' => 'product_variation',
'fields' => 'ids' 'fields' => 'ids'
)); ));
if ($children_by_price) : $lowest_price = '';
foreach ($children_by_price as $child) : if ($children) :
foreach ($children as $child) :
$child_price = get_post_meta($child, 'price', true); $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; endforeach;
endif; endif;
update_post_meta( $post_parent, 'price', $lowest_price );
} }
add_action('woocommerce_process_product_meta_variable', 'process_product_meta_variable'); 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']; $item_name = $item['name'];
if (isset($item['item_meta'])) : 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; endif;
$paypal_args['item_name_'.$item_loop] = $item_name; $paypal_args['item_name_'.$item_loop] = $item_name;