Simplify cart shipping template + text
Also prevents calculate shipping showing multiple times when multiple packages are present. @jameskoster @claudiosmweb
This commit is contained in:
parent
5372579546
commit
da8cae596b
|
@ -165,7 +165,13 @@ function wc_cart_totals_shipping_html() {
|
|||
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 ) );
|
||||
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
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,99 +14,64 @@
|
|||
* @see http://docs.woothemes.com/document/template-structure/
|
||||
* @author WooThemes
|
||||
* @package WooCommerce/Templates
|
||||
* @version 2.3.0
|
||||
* @version 2.5.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
<tr class="shipping">
|
||||
<th><?php
|
||||
if ( $show_package_details ) {
|
||||
printf( __( 'Shipping #%d', 'woocommerce' ), $index + 1 );
|
||||
} else {
|
||||
_e( 'Shipping', 'woocommerce' );
|
||||
}
|
||||
?></th>
|
||||
<th><?php echo $show_package_details && $index ? sprintf( __( 'Shipping #%d', 'woocommerce' ), $index + 1 ) : __( 'Shipping', 'woocommerce' ); ?></th>
|
||||
<td>
|
||||
<?php if ( ! empty( $available_methods ) ) : ?>
|
||||
<?php if ( empty( $available_methods ) ) : ?>
|
||||
|
||||
<?php if ( 1 === count( $available_methods ) ) :
|
||||
$method = current( $available_methods );
|
||||
<?php if ( ( WC()->countries->get_states( WC()->customer->get_shipping_country() ) && ! WC()->customer->get_shipping_state() ) || ! WC()->customer->get_shipping_postcode() ) : ?>
|
||||
|
||||
echo wc_cart_totals_shipping_method_label( $method ); ?>
|
||||
<input type="hidden" name="shipping_method[<?php echo $index; ?>]" data-index="<?php echo $index; ?>" id="shipping_method_<?php echo $index; ?>" value="<?php echo esc_attr( $method->id ); ?>" class="shipping_method" />
|
||||
|
||||
<?php elseif ( get_option( 'woocommerce_shipping_method_format' ) === 'select' ) : ?>
|
||||
|
||||
<select name="shipping_method[<?php echo $index; ?>]" data-index="<?php echo $index; ?>" id="shipping_method_<?php echo $index; ?>" class="shipping_method">
|
||||
<?php foreach ( $available_methods as $method ) : ?>
|
||||
<option value="<?php echo esc_attr( $method->id ); ?>" <?php selected( $method->id, $chosen_method ); ?>><?php echo wc_cart_totals_shipping_method_label( $method ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php echo wpautop( __( 'Shipping costs will be calculated once you have provided your address.', 'woocommerce' ) ); ?>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<ul id="shipping_method">
|
||||
<?php foreach ( $available_methods as $method ) : ?>
|
||||
<li>
|
||||
<input type="radio" name="shipping_method[<?php echo $index; ?>]" data-index="<?php echo $index; ?>" id="shipping_method_<?php echo $index; ?>_<?php echo sanitize_title( $method->id ); ?>" value="<?php echo esc_attr( $method->id ); ?>" <?php checked( $method->id, $chosen_method ); ?> class="shipping_method" />
|
||||
<label for="shipping_method_<?php echo $index; ?>_<?php echo sanitize_title( $method->id ); ?>"><?php echo wc_cart_totals_shipping_method_label( $method ); ?></label>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php echo apply_filters( is_cart() ? 'woocommerce_cart_no_shipping_available_html' : 'woocommerce_no_shipping_available_html', wpautop( __( 'There are no shipping methods available. Please double check your address, or contact us if you need any help.', 'woocommerce' ) ) ); ?>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php elseif ( ( WC()->countries->get_states( WC()->customer->get_shipping_country() ) && ! WC()->customer->get_shipping_state() ) || ! WC()->customer->get_shipping_postcode() ) : ?>
|
||||
<?php elseif ( 1 === count( $available_methods ) ) : ?>
|
||||
|
||||
<?php if ( is_cart() && get_option( 'woocommerce_enable_shipping_calc' ) === 'yes' ) : ?>
|
||||
<?php $method = current( $available_methods ); ?>
|
||||
<?php echo wc_cart_totals_shipping_method_label( $method ); ?>
|
||||
<input type="hidden" name="shipping_method[<?php echo $index; ?>]" data-index="<?php echo $index; ?>" id="shipping_method_<?php echo $index; ?>" value="<?php echo esc_attr( $method->id ); ?>" class="shipping_method" />
|
||||
|
||||
<p><?php _e( 'Please use the shipping calculator to see available shipping methods.', 'woocommerce' ); ?></p>
|
||||
<?php elseif ( 'select' === get_option( 'woocommerce_shipping_method_format' ) ) : ?>
|
||||
|
||||
<?php elseif ( is_cart() ) : ?>
|
||||
|
||||
<p><?php _e( 'Please continue to the checkout and enter your full address to see if there are any available shipping methods.', 'woocommerce' ); ?></p>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<p><?php _e( 'Please fill in your details to see available shipping methods.', 'woocommerce' ); ?></p>
|
||||
|
||||
<?php endif; ?>
|
||||
<select name="shipping_method[<?php echo $index; ?>]" data-index="<?php echo $index; ?>" id="shipping_method_<?php echo $index; ?>" class="shipping_method">
|
||||
<?php foreach ( $available_methods as $method ) : ?>
|
||||
<option value="<?php echo esc_attr( $method->id ); ?>" <?php selected( $method->id, $chosen_method ); ?>><?php echo wc_cart_totals_shipping_method_label( $method ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<?php if ( is_cart() ) : ?>
|
||||
|
||||
<?php echo apply_filters( 'woocommerce_cart_no_shipping_available_html',
|
||||
'<p>' . __( 'There are no shipping methods available. Please double check your address, or contact us if you need any help.', 'woocommerce' ) . '</p>'
|
||||
); ?>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<?php echo apply_filters( 'woocommerce_no_shipping_available_html',
|
||||
'<p>' . __( 'There are no shipping methods available. Please double check your address, or contact us if you need any help.', 'woocommerce' ) . '</p>'
|
||||
); ?>
|
||||
|
||||
<?php endif; ?>
|
||||
<ul id="shipping_method">
|
||||
<?php foreach ( $available_methods as $method ) : ?>
|
||||
<li>
|
||||
<input type="radio" name="shipping_method[<?php echo $index; ?>]" data-index="<?php echo $index; ?>" id="shipping_method_<?php echo $index; ?>_<?php echo sanitize_title( $method->id ); ?>" value="<?php echo esc_attr( $method->id ); ?>" <?php checked( $method->id, $chosen_method ); ?> class="shipping_method" />
|
||||
<label for="shipping_method_<?php echo $index; ?>_<?php echo sanitize_title( $method->id ); ?>"><?php echo wc_cart_totals_shipping_method_label( $method ); ?></label>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( $show_package_details ) : ?>
|
||||
<?php
|
||||
foreach ( $package['contents'] as $item_id => $values ) {
|
||||
if ( $values['data']->needs_shipping() ) {
|
||||
$product_names[] = $values['data']->get_title() . ' ×' . $values['quantity'];
|
||||
}
|
||||
$product_names[] = $values['data']->get_title() . ' ×' . $values['quantity'];
|
||||
}
|
||||
|
||||
echo '<p class="woocommerce-shipping-contents"><small>' . __( 'Shipping', 'woocommerce' ) . ': ' . implode( ', ', $product_names ) . '</small></p>';
|
||||
?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( is_cart() ) : ?>
|
||||
<?php if ( is_cart() && ! $index ) : ?>
|
||||
<?php woocommerce_shipping_calculator(); ?>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
|
|
Loading…
Reference in New Issue