From 0f59bd797df5c20c99642c2aebc43081be841f19 Mon Sep 17 00:00:00 2001 From: Geert De Deckere Date: Sat, 11 Feb 2012 14:46:54 +0100 Subject: [PATCH] Don't show a select list if there's only a single shipping method to choose from. Closes issue #605. --- templates/cart/totals.php | 95 +++++++++++++------------ templates/checkout/review-order.php | 103 +++++++++++++++------------- 2 files changed, 108 insertions(+), 90 deletions(-) diff --git a/templates/cart/totals.php b/templates/cart/totals.php index 554be734684..775fee20474 100644 --- a/templates/cart/totals.php +++ b/templates/cart/totals.php @@ -35,51 +35,60 @@ $available_methods = $woocommerce->shipping->get_available_shipping_methods(); 0) : - - echo ''; - - else : - - if ( !$woocommerce->customer->get_shipping_country() || !$woocommerce->customer->get_shipping_state() || !$woocommerce->customer->get_shipping_postcode() ) : + // If at least one shipping method is available + if ( $available_methods ) { + + // Prepare text labels with price for each shipping method + foreach ( $available_methods as $method ) { + $method->full_label = $method->label; + + if ( $method->cost > 0 ) { + $method->full_label .= ' — '; + + // Append price to label using the correct tax settings + if ( $woocommerce->cart->display_totals_ex_tax || ! $woocommerce->cart->prices_include_tax ) { + $method->full_label .= woocommerce_price( $method->cost ); + if ( $method->get_shipping_tax() > 0 && $woocommerce->cart->prices_include_tax ) { + $method->full_label .= ' '.$woocommerce->countries->ex_tax_or_vat(); + } + } else { + $method->full_label .= woocommerce_price( $method->cost + $method->get_shipping_tax() ); + if ( $method->get_shipping_tax() > 0 && ! $woocommerce->cart->prices_include_tax ) { + $method->full_label .= ' '.$woocommerce->countries->inc_tax_or_vat(); + } + } + } + } + + // Print a single available shipping method as plain text + if ( 1 === count( $available_methods ) ) { + + echo esc_html( $method->full_label ); + echo ''; + + // Show multiple shipping methods in a select list + } else { + + echo ''; + + } + + // No shipping methods are available + } else { + + if ( ! $woocommerce->customer->get_shipping_country() || ! $woocommerce->customer->get_shipping_state() || ! $woocommerce->customer->get_shipping_postcode() ) { echo '

'.__('Please fill in your details above to see available shipping methods.', 'woocommerce').'

'; - else : + } else { echo '

'.__('Sorry, it seems that there are no available shipping methods for your state. Please contact us if you require assistance or wish to make alternate arrangements.', 'woocommerce').'

'; - endif; - - endif; - + } + + } ?> diff --git a/templates/checkout/review-order.php b/templates/checkout/review-order.php index 0a1b505708d..4035a123a21 100755 --- a/templates/checkout/review-order.php +++ b/templates/checkout/review-order.php @@ -1,4 +1,12 @@ - +shipping->get_available_shipping_methods(); +?>
@@ -31,59 +39,60 @@
shipping->get_available_shipping_methods(); - - if (sizeof($available_methods)>0) : - - echo ''; - - else : - - if ( !$woocommerce->customer->get_shipping_country() || !$woocommerce->customer->get_shipping_state() || !$woocommerce->customer->get_shipping_postcode() ) : + echo esc_html( $method->full_label ); + echo ''; + + // Show multiple shipping methods in a select list + } else { + + echo ''; + + } + + // No shipping methods are available + } else { + + if ( ! $woocommerce->customer->get_shipping_country() || ! $woocommerce->customer->get_shipping_state() || ! $woocommerce->customer->get_shipping_postcode() ) { echo '

'.__('Please fill in your details above to see available shipping methods.', 'woocommerce').'

'; - else : + } else { echo '

'.__('Sorry, it seems that there are no available shipping methods for your state. Please contact us if you require assistance or wish to make alternate arrangements.', 'woocommerce').'

'; - endif; - - endif; - + } + + } ?>