From b9986dc15f5b987174ab8f6f16fc9e2f8ee58af5 Mon Sep 17 00:00:00 2001 From: vendidero Date: Fri, 25 Oct 2024 13:31:34 +0200 Subject: [PATCH] Hook adjustment. --- src/ShippingMethod/MethodHelper.php | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/ShippingMethod/MethodHelper.php b/src/ShippingMethod/MethodHelper.php index 5fd6bc1..343b898 100644 --- a/src/ShippingMethod/MethodHelper.php +++ b/src/ShippingMethod/MethodHelper.php @@ -31,26 +31,9 @@ public static function init() { add_filter( 'woocommerce_generate_shipping_provider_method_tabs_close_html', array( __CLASS__, 'render_method_tab_content_close' ), 10, 4 ); add_filter( 'woocommerce_generate_shipping_provider_method_configuration_sets_html', array( __CLASS__, 'render_method_configuration_sets' ), 10 ); + add_filter( 'woocommerce_cart_shipping_packages', array( __CLASS__, 'register_cart_items_to_pack' ) ); add_filter( 'woocommerce_shipping_methods', array( __CLASS__, 'register_shipping_methods' ) ); add_filter( 'woocommerce_hidden_order_itemmeta', array( __CLASS__, 'set_shipping_order_meta_hidden' ) ); - - add_filter( 'woocommerce_cart_shipping_packages', array( __CLASS__, 'register_cart_items_to_pack' ) ); - - add_action( - 'woocommerce_before_calculate_totals1', - function ( $cart ) { - remove_filter( 'woocommerce_cart_shipping_packages', array( __CLASS__, 'register_cart_items_to_pack' ) ); - - add_filter( - 'woocommerce_cart_shipping_packages', - function ( $package ) use ( $cart ) { - $package = self::register_cart_items_to_pack( $package, $cart ); - - return $package; - } - ); - } - ); } public static function set_shipping_order_meta_hidden( $meta ) { @@ -85,8 +68,6 @@ public static function register_cart_items_to_pack( $cart_contents ) { return $cart_contents; } - $cart = WC()->cart; - foreach ( $cart_contents as $index => $content ) { $package_data = array( 'total' => 0.0, @@ -157,6 +138,7 @@ public static function register_cart_items_to_pack( $cart_contents ) { * no item total amount (incl taxes) available. */ if ( 0 !== $cart_contents[ $index ]['cart_subtotal'] && apply_filters( 'woocommerce_gzd_shipments_prefer_cart_totals_over_cart_item_totals', false, $cart_contents ) ) { + $cart = WC()->cart; $total = (float) $cart->get_cart_contents_total(); if ( $cart->display_prices_including_tax() ) {