plugin_path() . '/templates/'; return $default_path . $template_name; } return $template; }, 10, 5); // Case #1 - WC()->cart->needs_shipping() && WC()->cart->show_shipping() $this->handle_cart_shipping_template(); // Case #2 - WC()->cart->needs_shipping() && 'yes' === get_option( 'woocommerce_enable_shipping_calc' ) $this->handle_cart_totals_template(); } private function handle_cart_shipping_template() { add_action( 'woocommerce_before_template_part', function ($template_name, $template_path, $located, $args) { if ($template_name !== 'cart/cart-shipping.php') { return; } ob_start(); }, 1, 4 ); add_action( 'woocommerce_after_template_part', function ($template_name, $template_path, $located, $args) { if ($template_name !== 'cart/cart-shipping.php') { return; } $result = ob_get_clean(); echo $this->replace_shipping_row($result); }, 1, 4 ); } private function handle_cart_totals_template() { add_action( 'woocommerce_before_template_part', function ($template_name, $template_path, $located, $args) { if ($template_name !== 'cart/cart-totals.php') { return; } ob_start(); }, 1, 4 ); add_action( 'woocommerce_after_template_part', function ($template_name, $template_path, $located, $args) { if ($template_name !== 'cart/cart-totals.php') { return; } $result = ob_get_clean(); if ( \WC()->cart->needs_shipping() && 'yes' === get_option('woocommerce_enable_shipping_calc') && ! \WC()->cart->show_shipping() ) { $result = preg_replace_callback( '/