diff --git a/includes/class-wc-cart.php b/includes/class-wc-cart.php index ff36aac5223..1eafc889f2b 100644 --- a/includes/class-wc-cart.php +++ b/includes/class-wc-cart.php @@ -2118,6 +2118,21 @@ class WC_Cart { return apply_filters( 'woocommerce_cart_subtotal', $cart_subtotal, $compound, $this ); } + /** + * Get the product row price per item. + * + * @params object product + * @return string formatted price + */ + public function get_product_price( $_product ) { + if ( $this->tax_display_cart == 'excl' ) + $product_price = $_product->get_price_excluding_tax(); + else + $product_price = $_product->get_price_including_tax(); + + return apply_filters( 'woocommerce_cart_product_price', woocommerce_price( $product_price ), $_product ); + } + /** * Get the product row subtotal. * diff --git a/includes/wc-deprecated-functions.php b/includes/wc-deprecated-functions.php index e17fd1640a0..ecd2e21cde8 100644 --- a/includes/wc-deprecated-functions.php +++ b/includes/wc-deprecated-functions.php @@ -12,8 +12,39 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly - function woocommerce_show_messages() { _deprecated_function( 'woocommerce_show_messages', '2.1', 'wc_print_messages' ); wc_show_messages(); +} + +/** + * Handle renamed filters + */ +global $wc_map_deprecated_filters; + +$wc_map_deprecated_filters = array( + 'woocommerce_cart_item_class' => 'woocommerce_cart_table_item_class', + 'woocommerce_cart_item_product_id' => 'hook_woocommerce_in_cart_product_id', + 'woocommerce_cart_item_thumbnail' => 'hook_woocommerce_in_cart_product_thumbnail', + 'woocommerce_cart_item_price' => 'woocommerce_cart_item_price_html', + 'woocommerce_cart_item_name' => 'woocommerce_in_cart_product_title', + 'woocommerce_order_item_class' => 'woocommerce_order_table_item_class', + 'woocommerce_order_item_name' => 'woocommerce_order_table_product_title' +); + +foreach ( $wc_map_deprecated_filters as $new => $old ) + add_filter( $new, 'woocommerce_deprecated_filter_mapping' ); + +function woocommerce_deprecated_filter_mapping( $data, $arg_1 = '', $arg_2 = '', $arg_3 = '' ) { + global $wc_map_deprecated_filters; + + $filter = current_filter(); + + if ( isset( $wc_map_deprecated_filters[ $filter ] ) ) + if ( has_filter( $wc_map_deprecated_filters[ $filter ] ) ) { + $data = apply_filters( $wc_map_deprecated_filters[ $filter ], $arg_1, $arg_2, $arg_3 ); + _deprecated_function( 'The ' . $wc_map_deprecated_filters[ $filter ] . ' filter', '2.1', $filter ); + } + + return $data; } \ No newline at end of file diff --git a/templates/cart/cart.php b/templates/cart/cart.php index 1f4a0c0695a..a9cc6994823 100755 --- a/templates/cart/cart.php +++ b/templates/cart/cart.php @@ -4,7 +4,7 @@ * * @author WooThemes * @package WooCommerce/Templates - * @version 1.6.4 + * @version 2.1.0 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -12,9 +12,8 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly global $woocommerce; wc_print_messages(); -?> - +do_action( 'woocommerce_before_cart' ); ?>
@@ -35,86 +34,77 @@ wc_print_messages(); cart->get_cart() ) > 0 ) { - foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) { - $_product = $values['data']; - $product_id = apply_filters('woocommerce_in_cart_product_id', $values['product_id'] ); + foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) { + $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); + $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key ); - if ( $_product->exists() && $values['quantity'] > 0 ) { - ?> - - - - ×', esc_url( $woocommerce->cart->get_remove_url( $cart_item_key ) ), __( 'Remove this item', 'woocommerce' ) ), $cart_item_key ); - ?> - + if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_cart_item_visible', true, $cart_item, $cart_item_key ) ) { + ?> + - - - get_image(), $values, $cart_item_key ); + + ×', esc_url( $woocommerce->cart->get_remove_url( $cart_item_key ) ), __( 'Remove this item', 'woocommerce' ) ), $cart_item_key ); + ?> + - if ( ! $_product->is_visible() ) - echo $thumbnail; - else - printf('%s', get_permalink( $product_id ), $thumbnail ); - ?> - + + get_image(), $cart_item, $cart_item_key ); - - - is_visible() ) - echo apply_filters( 'woocommerce_in_cart_product_title', $_product->get_title(), $values, $cart_item_key ); - else - echo apply_filters( 'woocommerce_in_cart_product_title', sprintf( '%s', get_permalink( $product_id ), $_product->get_title() ), $values, $cart_item_key ); + if ( ! $_product->is_visible() ) + echo $thumbnail; + else + printf( '%s', get_permalink( $product_id ), $thumbnail ); + ?> + - // Meta data - echo $woocommerce->cart->get_item_data( $values ); + + is_visible() ) + echo apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key ); + else + echo apply_filters( 'woocommerce_cart_item_name', sprintf( '%s', get_permalink( $product_id ), $_product->get_title() ), $cart_item, $cart_item_key ); - // Backorder notification - if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $values['quantity'] ) ) - echo '

' . __( 'Available on backorder', 'woocommerce' ) . '

'; - ?> - + // Meta data + echo $woocommerce->cart->get_item_data( $cart_item ); - - - get_price_excluding_tax() : $_product->get_price_including_tax(); + // Backorder notification + if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) ) + echo '

' . __( 'Available on backorder', 'woocommerce' ) . '

'; + ?> + - echo apply_filters('woocommerce_cart_item_price_html', woocommerce_price( $product_price ), $values, $cart_item_key ); - ?> - + + cart->get_product_price( $_product ), $cart_item, $cart_item_key ); + ?> + - - - is_sold_individually() ) { - $product_quantity = sprintf( '1 ', $cart_item_key ); - } else { + + is_sold_individually() ) { + $product_quantity = sprintf( '1 ', $cart_item_key ); + } else { - $step = apply_filters( 'woocommerce_quantity_input_step', '1', $_product ); - $min = apply_filters( 'woocommerce_quantity_input_min', '', $_product ); - $max = apply_filters( 'woocommerce_quantity_input_max', $_product->backorders_allowed() ? '' : $_product->get_stock_quantity(), $_product ); + $step = apply_filters( 'woocommerce_quantity_input_step', '1', $_product ); + $min = apply_filters( 'woocommerce_quantity_input_min', '', $_product ); + $max = apply_filters( 'woocommerce_quantity_input_max', $_product->backorders_allowed() ? '' : $_product->get_stock_quantity(), $_product ); - $product_quantity = sprintf( '
', $cart_item_key, $step, $min, $max, esc_attr( $values['quantity'] ) ); - } + $product_quantity = sprintf( '
', $cart_item_key, $step, $min, $max, esc_attr( $cart_item['quantity'] ) ); + } - echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key ); - ?> - + echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key ); + ?> + - - - cart->get_product_subtotal( $_product, $values['quantity'] ), $values, $cart_item_key ); - ?> - - - + cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ); + ?> + + + cart->get_cart() ) > 0 ) : ?> - cart->get_cart() as $cart_item_key => $cart_item ) : + cart->get_cart() as $cart_item_key => $cart_item ) { + $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); + $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key ); - $_product = $cart_item['data']; + if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_widget_cart_item_visible', true, $cart_item, $cart_item_key ) ) { - // Only display if allowed - if ( ! apply_filters('woocommerce_widget_cart_item_visible', true, $cart_item, $cart_item_key ) || ! $_product->exists() || $cart_item['quantity'] == 0 ) - continue; + $product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key ); + $thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key ); + $product_price = apply_filters( 'woocommerce_cart_item_price', $woocommerce->cart->get_product_price( $_product ), $cart_item, $cart_item_key ); - // Get price - $product_price = get_option( 'woocommerce_tax_display_cart' ) == 'excl' ? $_product->get_price_excluding_tax() : $_product->get_price_including_tax(); + ?> +
  • + + + - $product_price = apply_filters( 'woocommerce_cart_item_price_html', woocommerce_price( $product_price ), $cart_item, $cart_item_key ); - ?> + cart->get_item_data( $cart_item ); ?> -
  • - - - get_image(); ?> - - get_title(), $_product ); ?> - - - - cart->get_item_data( $cart_item ); ?> - - ' . sprintf( '%s × %s', $cart_item['quantity'], $product_price ) . '', $cart_item, $cart_item_key ); ?> -
  • - - + ' . sprintf( '%s × %s', $cart_item['quantity'], $product_price ) . '', $cart_item, $cart_item_key ); ?> + + @@ -71,4 +67,4 @@ global $woocommerce; - + \ No newline at end of file diff --git a/templates/checkout/review-order.php b/templates/checkout/review-order.php index 206a93481af..469bf44cfb1 100644 --- a/templates/checkout/review-order.php +++ b/templates/checkout/review-order.php @@ -4,7 +4,7 @@ * * @author WooThemes * @package WooCommerce/Templates - * @version 1.6.4 + * @version 2.1.0 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -115,22 +115,24 @@ $available_methods = $woocommerce->shipping->get_available_shipping_methods(); cart->get_cart())>0) : - foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) : - $_product = $values['data']; - if ($_product->exists() && $values['quantity']>0) : - echo ' - - ' . - apply_filters( 'woocommerce_checkout_product_title', $_product->get_title(), $_product ) . ' ' . - apply_filters( 'woocommerce_checkout_item_quantity', '× ' . $values['quantity'] . '', $values, $cart_item_key ) . - $woocommerce->cart->get_item_data( $values ) . - ' - ' . apply_filters( 'woocommerce_checkout_item_subtotal', $woocommerce->cart->get_product_subtotal( $_product, $values['quantity'] ), $values, $cart_item_key ) . ' - '; - endif; - endforeach; - endif; + foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) { + $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); + + if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_checkout_cart_item_visible', true, $cart_item, $cart_item_key ) ) { + ?> + + + get_title(), $cart_item, $cart_item_key ); ?> + ' . sprintf( '× %s', $cart_item['quantity'] ) . '', $cart_item, $cart_item_key ); ?> + cart->get_item_data( $cart_item ); ?> + + + cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ); ?> + + + diff --git a/templates/emails/email-order-items.php b/templates/emails/email-order-items.php index 3065d9ef0ed..8b234dc932e 100644 --- a/templates/emails/email-order-items.php +++ b/templates/emails/email-order-items.php @@ -4,32 +4,30 @@ * * @author WooThemes * @package WooCommerce/Templates/Emails - * @version 2.0.3 + * @version 2.1.0 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly global $woocommerce; -foreach ($items as $item) : - - // Get/prep product data - $_product = $order->get_product_from_item( $item ); - $item_meta = new WC_Order_Item_Meta( $item['item_meta'] ); - $image = ($show_image) ? 'Product Image' : ''; - +foreach ( $items as $item ) : + $_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item ); + $item_meta = new WC_Order_Item_Meta( $item['item_meta'] ); ?> id ), 'thumbnail') ) .'" alt="Product Image" height="' . $image_size[1] . '" width="' . $image_size[0] . '" style="vertical-align:middle; margin-right: 10px;" />', $item ); // Product name - echo apply_filters( 'woocommerce_order_product_title', $item['name'], $_product ); + echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item ); // SKU - echo ($show_sku && $_product->get_sku()) ? ' (#' . $_product->get_sku() . ')' : ''; + if ( $show_sku && $_product->get_sku() ) + echo ' (#' . $_product->get_sku() . ')'; // File URLs if ( $show_download_links && $_product->exists() && $_product->is_downloadable() ) { @@ -44,7 +42,7 @@ foreach ($items as $item) : $filename = woocommerce_get_filename_from_url( $file_url ); if ( count( $download_file_urls ) > 1 ) { - echo sprintf( __('Download %d:', 'woocommerce' ), $i + 1 ); + echo sprintf( __( 'Download %d:', 'woocommerce' ), $i + 1 ); } elseif ( $i == 0 ) echo __( 'Download:', 'woocommerce' ); @@ -55,16 +53,17 @@ foreach ($items as $item) : } // Variation - echo ($item_meta->meta) ? '
    ' . nl2br( $item_meta->display( true, true ) ) . '' : ''; + if ( $item_meta->meta ) + echo '
    ' . nl2br( $item_meta->display( true, true ) ) . ''; ?> get_formatted_line_subtotal( $item ); ?> - id, '_purchase_note', true)) : ?> + id, '_purchase_note', true ) ) : ?> - + diff --git a/templates/emails/plain/email-order-items.php b/templates/emails/plain/email-order-items.php index 3a8292ce0bb..ca503cfb5cf 100644 --- a/templates/emails/plain/email-order-items.php +++ b/templates/emails/plain/email-order-items.php @@ -4,7 +4,7 @@ * * @author WooThemes * @package WooCommerce/Templates/Emails/Plain - * @version 2.0.0 + * @version 2.1.0 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -12,14 +12,15 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly global $woocommerce; foreach ( $items as $item ) : + $_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item ); + $item_meta = new WC_Order_Item_Meta( $item['item_meta'] ); - // Get/prep product data - $_product = $order->get_product_from_item( $item ); - $item_meta = new WC_Order_Item_Meta( $item['item_meta'] ); + // Title + echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item ); - // Title, sku, qty, price - echo apply_filters( 'woocommerce_order_product_title', $item['name'], $_product ); - echo $show_sku && $_product->get_sku() ? ' (#' . $_product->get_sku() . ')' : ''; + // SKU + if ( $show_sku && $_product->get_sku() ) + echo ' (#' . $_product->get_sku() . ')'; // Variation echo $item_meta->meta ? "\n" . nl2br( $item_meta->display( true, true ) ) : ''; diff --git a/templates/order/order-details.php b/templates/order/order-details.php index 8a754a6e71c..09302baac8c 100755 --- a/templates/order/order-details.php +++ b/templates/order/order-details.php @@ -35,51 +35,58 @@ $order = new WC_Order( $order_id ); get_items())>0) { + if ( sizeof( $order->get_items() ) > 0 ) { - foreach($order->get_items() as $item) { - $_product = get_product( $item['variation_id'] ? $item['variation_id'] : $item['product_id'] ); + foreach( $order->get_items() as $item ) { + $_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item ); + $item_meta = new WC_Order_Item_Meta( $item['item_meta'] ); - echo ' - '; + ?> + + + is_visible() ) + echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item ); + else + echo apply_filters( 'woocommerce_order_item_name', sprintf( '%s', get_permalink( $item['product_id'] ), $item['name'] ), $item ); - if ( $_product && ! $_product->is_visible() ) - echo apply_filters( 'woocommerce_order_table_product_title', $item['name'], $item ); - else - echo apply_filters( 'woocommerce_order_table_product_title', sprintf( '%s', get_permalink( $item['product_id'] ), $item['name'] ), $item ); + echo apply_filters( 'woocommerce_order_item_quantity', ' ' . sprintf( '× %s', $item['qty'] ) . '', $item ); - echo apply_filters( 'woocommerce_order_table_item_quantity', ' × ' . $item['qty'] . '', $item ); + $item_meta->display(); - $item_meta = new WC_Order_Item_Meta( $item['item_meta'] ); - $item_meta->display(); + if ( $_product && $_product->exists() && $_product->is_downloadable() && $order->is_download_permitted() ) { - if ( $_product && $_product->exists() && $_product->is_downloadable() && $order->is_download_permitted() ) { + $download_file_urls = $order->get_downloadable_file_urls( $item['product_id'], $item['variation_id'], $item ); - $download_file_urls = $order->get_downloadable_file_urls( $item['product_id'], $item['variation_id'], $item ); + $i = 0; + $links = array(); - $i = 0; - $links = array(); + foreach ( $download_file_urls as $file_url => $download_file_url ) { - foreach ( $download_file_urls as $file_url => $download_file_url ) { + $filename = woocommerce_get_filename_from_url( $file_url ); - $filename = woocommerce_get_filename_from_url( $file_url ); + $links[] = '' . sprintf( __( 'Download file%s', 'woocommerce' ), ( count( $download_file_urls ) > 1 ? ' ' . ( $i + 1 ) . ': ' : ': ' ) ) . $filename . ''; - $links[] = '' . sprintf( __( 'Download file%s', 'woocommerce' ), ( count( $download_file_urls ) > 1 ? ' ' . ( $i + 1 ) . ': ' : ': ' ) ) . $filename . ''; + $i++; + } - $i++; - } + echo implode( '
    ', $links ); + } + ?> + + + get_formatted_line_subtotal( $item ); ?> + + + ', $links ); + if ( in_array( $order->status, array( 'processing', 'completed' ) ) && ( $purchase_note = get_post_meta( $_product->id, '_purchase_note', true ) ) ) { + ?> + + + + ' . $order->get_formatted_line_subtotal( $item ) . ''; - - // Show any purchase notes - if ($order->status=='completed' || $order->status=='processing') { - if ($purchase_note = get_post_meta( $_product->id, '_purchase_note', true)) - echo '' . apply_filters('the_content', $purchase_note) . ''; - } - } }