Created
April 1, 2021 19:54
-
-
Save luiseduardobraschi/1eb229aaeb0d665ccfc11dc39d58a517 to your computer and use it in GitHub Desktop.
[WooCommerce] Moving cart calculator to the top of the cart collaterals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Moving cart calculator to the top of the cart collaterals | |
*/ | |
add_filter( 'woocommerce_shipping_show_shipping_calculator', '__return_false' ); | |
add_action( 'woocommerce_cart_totals_before_shipping', function(){ | |
$packages = WC()->shipping()->get_packages(); | |
$first_package = array_shift( $packages ); | |
$formatted_destination = WC()->countries->get_formatted_address( $first_package['destination'], ', ' ); | |
?> | |
<tr> | |
<td colspan="2"> | |
<p> | |
<?php | |
if ( $formatted_destination ) { | |
// Translators: $s shipping destination. | |
printf( esc_html__( 'Shipping to %s.', 'woocommerce' ) . ' ', '<strong>' . esc_html( $formatted_destination ) . '</strong>' ); | |
$calculator_text = esc_html__( 'Change address', 'woocommerce' ); | |
} else { | |
echo wp_kses_post( apply_filters( 'woocommerce_shipping_estimate_html', __( 'Shipping options will be updated during checkout.', 'woocommerce' ) ) ); | |
} | |
?> | |
</p> | |
<?php woocommerce_shipping_calculator(); ?> | |
</td> | |
</tr> | |
<?php | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment