woocommerce/templates/cart/shipping-methods.php

69 lines
2.8 KiB
PHP
Raw Normal View History

2012-11-27 16:22:47 +00:00
<?php
/**
* Shipping Methods Display
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 1.7.0
*/
2012-11-27 16:22:47 +00:00
global $woocommerce;
// 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 ) {
if ( $woocommerce->cart->display_totals_ex_tax || ! $woocommerce->cart->prices_include_tax || $woocommerce->customer->is_vat_exempt() ) {
$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 wp_kses_post( $method->full_label ) . '<input type="hidden" name="shipping_method" id="shipping_method" value="' . esc_attr( $method->id ) . '" />';
// Show select boxes for methods
} elseif ( get_option('woocommerce_shipping_method_format') == 'select' ) {
echo '<select name="shipping_method" id="shipping_method">';
foreach ( $available_methods as $method )
echo '<option value="' . esc_attr( $method->id ) . '" ' . selected( $method->id, $woocommerce->session->chosen_shipping_method, false ) . '>' . wp_kses_post( $method->full_label ) . '</option>';
echo '</select>';
2012-11-27 16:22:47 +00:00
// Show radio buttons for methods
} else {
echo '<ul id="shipping_method">';
foreach ( $available_methods as $method )
echo '<li><input type="radio" name="shipping_method" id="shipping_method_' . sanitize_title( $method->id ) . '" value="' . esc_attr( $method->id ) . '" ' . checked( $method->id, $woocommerce->session->chosen_shipping_method, false) . ' /> <label for="shipping_method_' . sanitize_title( $method->id ) . '">' . wp_kses_post( $method->full_label ) . '</label></li>';
echo '</ul>';
}
// No shipping methods are available
} else {
if ( ! $woocommerce->customer->get_shipping_country() || ! $woocommerce->customer->get_shipping_state() || ! $woocommerce->customer->get_shipping_postcode() ) {
echo '<p>' . __( 'Please fill in your details to see available shipping methods.', 'woocommerce' ) . '</p>';
} else {
echo '<p>' . __( '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' ) . '</p>';
}
}