diff --git a/assets/js/admin/meta-boxes-order.js b/assets/js/admin/meta-boxes-order.js index 18bfdce16c2..ce9c9c9f704 100644 --- a/assets/js/admin/meta-boxes-order.js +++ b/assets/js/admin/meta-boxes-order.js @@ -750,7 +750,7 @@ jQuery( function ( $ ) { $.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) { if ( true === response.success ) { // Redirect to same page for show the refunded status - window.location.href = window.location.href; + window.location.reload(); } else { window.alert( response.data.error ); wc_meta_boxes_order_items.reload_items(); diff --git a/assets/js/admin/meta-boxes-product-variation.js b/assets/js/admin/meta-boxes-product-variation.js index 560a868ede4..fdec680dd5b 100644 --- a/assets/js/admin/meta-boxes-product-variation.js +++ b/assets/js/admin/meta-boxes-product-variation.js @@ -329,7 +329,13 @@ jQuery( function( $ ) { .on( 'change', '#variable_product_options .woocommerce_variations :input', this.input_changed ) .on( 'change', '.variations-defaults select', this.defaults_changed ); - $( 'form#post' ).on( 'submit', this.save_on_submit ); + var postForm = $( 'form#post' ); + + postForm.on( 'submit', this.save_on_submit ); + + $( 'input:submit', postForm ).bind( 'click keypress', function() { + postForm.data( 'callerid', this.id ); + }); $( '.wc-metaboxes-wrapper' ).on( 'click', 'a.do_variation_action', this.do_variation_action ); }, @@ -524,7 +530,14 @@ jQuery( function( $ ) { * After saved, continue with form submission */ save_on_submit_done: function() { - $( 'form#post' ).submit(); + var postForm = $( 'form#post' ), + callerid = postForm.data( 'callerid' ); + + if ( 'publish' === callerid ) { + postForm.append('').submit(); + } else { + postForm.append('').submit(); + } }, /** diff --git a/includes/admin/meta-boxes/views/html-product-data-variations.php b/includes/admin/meta-boxes/views/html-product-data-variations.php index 36c6a32d8b6..c6ebfac5006 100644 --- a/includes/admin/meta-boxes/views/html-product-data-variations.php +++ b/includes/admin/meta-boxes/views/html-product-data-variations.php @@ -33,11 +33,11 @@ if ( ! defined( 'ABSPATH' ) ) { is_taxonomy() ) : ?> get_terms() as $option ) : ?> - + get_options() as $option ) : ?> - + diff --git a/includes/admin/meta-boxes/views/html-variation-admin.php b/includes/admin/meta-boxes/views/html-variation-admin.php index 06e3823884f..5e1cef7b3ea 100644 --- a/includes/admin/meta-boxes/views/html-variation-admin.php +++ b/includes/admin/meta-boxes/views/html-variation-admin.php @@ -35,11 +35,11 @@ if ( ! defined( 'ABSPATH' ) ) { is_taxonomy() ) : ?> get_terms() as $option ) : ?> - + get_options() as $option ) : ?> - + diff --git a/includes/class-wc-cart-totals.php b/includes/class-wc-cart-totals.php index 538977363f0..55bf6d5e072 100644 --- a/includes/class-wc-cart-totals.php +++ b/includes/class-wc-cart-totals.php @@ -579,10 +579,28 @@ final class WC_Cart_Totals { $taxes[ $rate_id ] += $this->round_line_tax( $rate ); } } + $taxes = $this->round_merged_taxes( $taxes ); return $in_cents ? $taxes : wc_remove_number_precision_deep( $taxes ); } + /** + * Round merged taxes. + * + * @since 3.5.4 + * @param array $taxes Taxes to round. + * @return array + */ + protected function round_merged_taxes( $taxes ) { + if ( $this->round_at_subtotal() ) { + foreach ( $taxes as $rate_id => $tax ) { + $taxes[ $rate_id ] = wc_round_tax_total( $tax, 0 ); + } + } + + return $taxes; + } + /** * Combine item taxes into a single array, preserving keys. * diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index ff553d8ec82..ff71246af43 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -2908,14 +2908,14 @@ if ( ! function_exists( 'wc_dropdown_variation_attribute_options' ) ) { foreach ( $terms as $term ) { if ( in_array( $term->slug, $options, true ) ) { - $html .= ''; + $html .= ''; } } } else { foreach ( $options as $option ) { // This handles < 2.4.0 bw compatibility where text attributes were not sanitized. $selected = sanitize_title( $args['selected'] ) === $args['selected'] ? selected( $args['selected'], sanitize_title( $option ), false ) : selected( $args['selected'], $option, false ); - $html .= ''; + $html .= ''; } } } @@ -3406,7 +3406,7 @@ function wc_get_formatted_cart_item_data( $cart_item, $flat = false ) { $label = wc_attribute_label( $taxonomy ); } else { // If this is a custom option slug, get the options name. - $value = apply_filters( 'woocommerce_variation_option_name', $value ); + $value = apply_filters( 'woocommerce_variation_option_name', $value, null, $taxonomy, $cart_item['data'] ); $label = wc_attribute_label( str_replace( 'attribute_', '', $name ), $cart_item['data'] ); } diff --git a/templates/order/form-tracking.php b/templates/order/form-tracking.php index 20d34e32512..be4eb2d9cc2 100644 --- a/templates/order/form-tracking.php +++ b/templates/order/form-tracking.php @@ -12,7 +12,7 @@ * * @see https://docs.woocommerce.com/document/template-structure/ * @package WooCommerce/Templates - * @version 3.4.0 + * @version 3.6.0 */ defined( 'ABSPATH' ) || exit; @@ -20,7 +20,7 @@ defined( 'ABSPATH' ) || exit; global $post; ?> -
+

diff --git a/tests/unit-tests/cart/cart.php b/tests/unit-tests/cart/cart.php index d3115a1d998..41c01201ff8 100644 --- a/tests/unit-tests/cart/cart.php +++ b/tests/unit-tests/cart/cart.php @@ -12,6 +12,95 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { WC()->customer->set_is_vat_exempt( false ); } + /** + * Test tax rounding. + * Ticket: + * https://github.com/woocommerce/woocommerce/issues/21021 + */ + public function test_cart_get_total_issue_21021() { + update_option( 'woocommerce_prices_include_tax', 'yes' ); + update_option( 'woocommerce_calc_taxes', 'yes' ); + update_option( 'woocommerce_tax_round_at_subtotal', 'yes' ); + + $tax_rate = array( + 'tax_rate_country' => '', + 'tax_rate_state' => '', + 'tax_rate' => '23.0000', + 'tax_rate_name' => 'TAX23', + 'tax_rate_priority' => '1', + 'tax_rate_compound' => '0', + 'tax_rate_shipping' => '1', + 'tax_rate_order' => '1', + 'tax_rate_class' => '23percent', + ); + $tax_rate_23 = WC_Tax::_insert_tax_rate( $tax_rate ); + + $tax_rate = array( + 'tax_rate_country' => '', + 'tax_rate_state' => '', + 'tax_rate' => '5.0000', + 'tax_rate_name' => 'TAX5', + 'tax_rate_priority' => '2', + 'tax_rate_compound' => '0', + 'tax_rate_shipping' => '0', + 'tax_rate_order' => '1', + 'tax_rate_class' => '5percent', + ); + $tax_rate_5 = WC_Tax::_insert_tax_rate( $tax_rate ); + + // Create product with price 19 + $product = WC_Helper_Product::create_simple_product(); + $product->set_price( 19 ); + $product->set_regular_price( 19 ); + $product->set_tax_class( '5percent' ); + $product->save(); + + // Create product with price 59 + $product2 = WC_Helper_Product::create_simple_product(); + $product2->set_price( 59 ); + $product2->set_regular_price( 59 ); + $product->set_tax_class( '5percent' ); + $product2->save(); + + // Create a flat rate method. + $flat_rate_settings = array( + 'enabled' => 'yes', + 'title' => 'Flat rate', + 'availability' => 'all', + 'countries' => '', + 'tax_status' => 'taxable', + 'cost' => '8.05', + ); + update_option( 'woocommerce_flat_rate_settings', $flat_rate_settings ); + update_option( 'woocommerce_flat_rate', array() ); + WC_Cache_Helper::get_transient_version( 'shipping', true ); + WC()->shipping->load_shipping_methods(); + + WC()->cart->empty_cart(); + + // Set the flat_rate shipping method + WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) ); + + // Add product to cart x1, calc and test + WC()->cart->add_to_cart( $product->get_id(), 1 ); + WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) ); + WC()->cart->calculate_totals(); + $this->assertEquals( 28.9, WC()->cart->total ); + + // Add product2 to cart + WC()->cart->add_to_cart( $product2->get_id(), 1 ); + WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) ); + WC()->cart->calculate_totals(); + $this->assertEquals( 87.9, WC()->cart->total ); + + WC_Helper_Product::delete_product( $product->get_id() ); + WC_Helper_Product::delete_product( $product2->get_id() ); + + WC_Tax::_delete_tax_rate( $tax_rate_23 ); + WC_Tax::_delete_tax_rate( $tax_rate_5 ); + + } + /** * Test some discount logic which has caused issues in the past. * Ticket: