暫無描述

cart-shipping.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Shipping Methods Display
  4. *
  5. * In 2.1 we show methods per package. This allows for multiple methods per order if so desired.
  6. *
  7. * This template can be overridden by copying it to yourtheme/woocommerce/cart/cart-shipping.php.
  8. *
  9. * HOWEVER, on occasion WooCommerce will need to update template files and you
  10. * (the theme developer) will need to copy the new files to your theme to
  11. * maintain compatibility. We try to do this as little as possible, but it does
  12. * happen. When this occurs the version of the template file will be bumped and
  13. * the readme will list any important changes.
  14. *
  15. * @see https://docs.woocommerce.com/document/template-structure/
  16. * @package WooCommerce\Templates
  17. * @version 3.6.0
  18. */
  19. defined( 'ABSPATH' ) || exit;
  20. $formatted_destination = isset( $formatted_destination ) ? $formatted_destination : WC()->countries->get_formatted_address( $package['destination'], ', ' );
  21. $has_calculated_shipping = ! empty( $has_calculated_shipping );
  22. $show_shipping_calculator = ! empty( $show_shipping_calculator );
  23. $calculator_text = '';
  24. ?>
  25. <tr class="woocommerce-shipping-totals shipping">
  26. <th><?php echo wp_kses_post( $package_name ); ?></th>
  27. <td data-title="<?php echo esc_attr( $package_name ); ?>">
  28. <?php if ( $available_methods ) : ?>
  29. <ul id="shipping_method" class="woocommerce-shipping-methods">
  30. <?php foreach ( $available_methods as $method ) : ?>
  31. <li>
  32. <?php
  33. if ( 1 < count( $available_methods ) ) {
  34. printf( '<input type="radio" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" %4$s />', $index, esc_attr( sanitize_title( $method->id ) ), esc_attr( $method->id ), checked( $method->id, $chosen_method, false ) ); // WPCS: XSS ok.
  35. } else {
  36. printf( '<input type="hidden" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" />', $index, esc_attr( sanitize_title( $method->id ) ), esc_attr( $method->id ) ); // WPCS: XSS ok.
  37. }
  38. printf( '<label for="shipping_method_%1$s_%2$s">%3$s</label>', $index, esc_attr( sanitize_title( $method->id ) ), wc_cart_totals_shipping_method_label( $method ) ); // WPCS: XSS ok.
  39. do_action( 'woocommerce_after_shipping_rate', $method, $index );
  40. ?>
  41. </li>
  42. <?php endforeach; ?>
  43. </ul>
  44. <?php if ( is_cart() ) : ?>
  45. <p class="woocommerce-shipping-destination">
  46. <?php
  47. if ( $formatted_destination ) {
  48. // Translators: $s shipping destination.
  49. printf( esc_html__( 'Shipping to %s.', 'woocommerce' ) . ' ', '<strong>' . esc_html( $formatted_destination ) . '</strong>' );
  50. $calculator_text = esc_html__( 'Change address', 'woocommerce' );
  51. } else {
  52. echo wp_kses_post( apply_filters( 'woocommerce_shipping_estimate_html', __( 'Shipping options will be updated during checkout.', 'woocommerce' ) ) );
  53. }
  54. ?>
  55. </p>
  56. <?php endif; ?>
  57. <?php
  58. elseif ( ! $has_calculated_shipping || ! $formatted_destination ) :
  59. if ( is_cart() && 'no' === get_option( 'woocommerce_enable_shipping_calc' ) ) {
  60. echo wp_kses_post( apply_filters( 'woocommerce_shipping_not_enabled_on_cart_html', __( 'Shipping costs are calculated during checkout.', 'woocommerce' ) ) );
  61. } else {
  62. echo wp_kses_post( apply_filters( 'woocommerce_shipping_may_be_available_html', __( 'Enter your address to view shipping options.', 'woocommerce' ) ) );
  63. }
  64. elseif ( ! is_cart() ) :
  65. echo wp_kses_post( apply_filters( 'woocommerce_no_shipping_available_html', __( 'There are no shipping options available. Please ensure that your address has been entered correctly, or contact us if you need any help.', 'woocommerce' ) ) );
  66. else :
  67. // Translators: $s shipping destination.
  68. echo wp_kses_post( apply_filters( 'woocommerce_cart_no_shipping_available_html', sprintf( esc_html__( 'No shipping options were found for %s.', 'woocommerce' ) . ' ', '<strong>' . esc_html( $formatted_destination ) . '</strong>' ) ) );
  69. $calculator_text = esc_html__( 'Enter a different address', 'woocommerce' );
  70. endif;
  71. ?>
  72. <?php if ( $show_package_details ) : ?>
  73. <?php echo '<p class="woocommerce-shipping-contents"><small>' . esc_html( $package_details ) . '</small></p>'; ?>
  74. <?php endif; ?>
  75. <?php if ( $show_shipping_calculator ) : ?>
  76. <?php woocommerce_shipping_calculator( $calculator_text ); ?>
  77. <?php endif; ?>
  78. </td>
  79. </tr>