I have a Woocommerce One Page Checkout website with currently one product. Everything is working so far but for some reason I don’t see the shippingcosts displayed.
The price calculcation is correct and when I go to the paymentportal the shippingcosts are added to the total price but the shipping costs are not displayed.
To give some insight in my search for the solution:
Rendering all the data happens in /woocommerce/templates/checkout/review-order.php
There is called:
<?php wc_cart_totals_shipping_html(); ?>
This function can be found in /woocommcerce/includes/wc-cart-functions.php
There the code being executed is:
/**
* Get shipping methods
*
* @access public
* @return void
*/
function wc_custom_cart_totals_shipping_html() {
$packages = WC()->shipping->get_packages();
foreach ( $packages as $i => $package ) {
$chosen_method = isset( WC()->session->chosen_shipping_methods[ $i ] ) ? WC()->session->chosen_shipping_methods[ $i ] : '';
wc_get_template( 'cart/cart-shipping.php', array( 'package' => $package, 'available_methods' => $package['rates'], 'show_package_details' => ( sizeof( $packages ) > 1 ), 'index' => $i, 'chosen_method' => $chosen_method ) );
}
}
The problem is that $packages = WC()->shipping->get_packages();
returns an empty array.
The function get_packages in /woocommerce/includes/class-wc-shipping.php is as follows:
/**
* Get packages
* @return array
*/
public function get_packages() {
return $this->packages;
}
So property $this->packages is not set. This property is set in function calculate_shipping in the same file /woocommerce/includes/class-wc-shipping.php
I tried calling that function right before $packages = WC()->shipping->get_packages();
but that did not work.
Is there someone who can help me out? Please note that I don’t have much experience in programming in WordPress.
Kind regards,
Pim
Had the same issue but managed to figure it out after a while, you need to call
This will populate the packages and then you can use
To show a list of the available shipping methods wherever you like