Nav apraksta

shipping-calculator.php 4.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Shipping Calculator
  4. *
  5. * This template can be overridden by copying it to yourtheme/woocommerce/cart/shipping-calculator.php.
  6. *
  7. * HOWEVER, on occasion WooCommerce will need to update template files and you
  8. * (the theme developer) will need to copy the new files to your theme to
  9. * maintain compatibility. We try to do this as little as possible, but it does
  10. * happen. When this occurs the version of the template file will be bumped and
  11. * the readme will list any important changes.
  12. *
  13. * @see https://docs.woocommerce.com/document/template-structure/
  14. * @package WooCommerce\Templates
  15. * @version 4.0.0
  16. */
  17. defined( 'ABSPATH' ) || exit;
  18. do_action( 'woocommerce_before_shipping_calculator' ); ?>
  19. <form class="woocommerce-shipping-calculator" action="<?php echo esc_url( wc_get_cart_url() ); ?>" method="post">
  20. <?php printf( '<a href="#" class="shipping-calculator-button">%s</a>', esc_html( ! empty( $button_text ) ? $button_text : __( 'Calculate shipping', 'woocommerce' ) ) ); ?>
  21. <section class="shipping-calculator-form" style="display:none;">
  22. <?php if ( apply_filters( 'woocommerce_shipping_calculator_enable_country', true ) ) : ?>
  23. <p class="form-row form-row-wide" id="calc_shipping_country_field">
  24. <select name="calc_shipping_country" id="calc_shipping_country" class="country_to_state country_select" rel="calc_shipping_state">
  25. <option value="default"><?php esc_html_e( 'Select a country / region&hellip;', 'woocommerce' ); ?></option>
  26. <?php
  27. foreach ( WC()->countries->get_shipping_countries() as $key => $value ) {
  28. echo '<option value="' . esc_attr( $key ) . '"' . selected( WC()->customer->get_shipping_country(), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
  29. }
  30. ?>
  31. </select>
  32. </p>
  33. <?php endif; ?>
  34. <?php if ( apply_filters( 'woocommerce_shipping_calculator_enable_state', true ) ) : ?>
  35. <p class="form-row form-row-wide" id="calc_shipping_state_field">
  36. <?php
  37. $current_cc = WC()->customer->get_shipping_country();
  38. $current_r = WC()->customer->get_shipping_state();
  39. $states = WC()->countries->get_states( $current_cc );
  40. if ( is_array( $states ) && empty( $states ) ) {
  41. ?>
  42. <input type="hidden" name="calc_shipping_state" id="calc_shipping_state" placeholder="<?php esc_attr_e( 'State / County', 'woocommerce' ); ?>" />
  43. <?php
  44. } elseif ( is_array( $states ) ) {
  45. ?>
  46. <span>
  47. <select name="calc_shipping_state" class="state_select" id="calc_shipping_state" data-placeholder="<?php esc_attr_e( 'State / County', 'woocommerce' ); ?>">
  48. <option value=""><?php esc_html_e( 'Select an option&hellip;', 'woocommerce' ); ?></option>
  49. <?php
  50. foreach ( $states as $ckey => $cvalue ) {
  51. echo '<option value="' . esc_attr( $ckey ) . '" ' . selected( $current_r, $ckey, false ) . '>' . esc_html( $cvalue ) . '</option>';
  52. }
  53. ?>
  54. </select>
  55. </span>
  56. <?php
  57. } else {
  58. ?>
  59. <input type="text" class="input-text" value="<?php echo esc_attr( $current_r ); ?>" placeholder="<?php esc_attr_e( 'State / County', 'woocommerce' ); ?>" name="calc_shipping_state" id="calc_shipping_state" />
  60. <?php
  61. }
  62. ?>
  63. </p>
  64. <?php endif; ?>
  65. <?php if ( apply_filters( 'woocommerce_shipping_calculator_enable_city', true ) ) : ?>
  66. <p class="form-row form-row-wide" id="calc_shipping_city_field">
  67. <input type="text" class="input-text" value="<?php echo esc_attr( WC()->customer->get_shipping_city() ); ?>" placeholder="<?php esc_attr_e( 'City', 'woocommerce' ); ?>" name="calc_shipping_city" id="calc_shipping_city" />
  68. </p>
  69. <?php endif; ?>
  70. <?php if ( apply_filters( 'woocommerce_shipping_calculator_enable_postcode', true ) ) : ?>
  71. <p class="form-row form-row-wide" id="calc_shipping_postcode_field">
  72. <input type="text" class="input-text" value="<?php echo esc_attr( WC()->customer->get_shipping_postcode() ); ?>" placeholder="<?php esc_attr_e( 'Postcode / ZIP', 'woocommerce' ); ?>" name="calc_shipping_postcode" id="calc_shipping_postcode" />
  73. </p>
  74. <?php endif; ?>
  75. <p><button type="submit" name="calc_shipping" value="1" class="button"><?php esc_html_e( 'Update', 'woocommerce' ); ?></button></p>
  76. <?php wp_nonce_field( 'woocommerce-shipping-calculator', 'woocommerce-shipping-calculator-nonce' ); ?>
  77. </section>
  78. </form>
  79. <?php do_action( 'woocommerce_after_shipping_calculator' ); ?>