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.woothemes.com/document/template-structure/ |
14
|
|
|
* @author WooThemes |
15
|
|
|
* @package WooCommerce/Templates |
16
|
|
|
* @version 2.0.8 |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
20
|
|
|
exit; // Exit if accessed directly |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
if ( 'no' === get_option( 'woocommerce_enable_shipping_calc' ) || ! WC()->cart->needs_shipping() ) { |
24
|
|
|
return; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
?> |
28
|
|
|
|
29
|
|
|
<?php do_action( 'woocommerce_before_shipping_calculator' ); ?> |
30
|
|
|
|
31
|
|
|
<form class="woocommerce-shipping-calculator" action="<?php echo esc_url( wc_get_cart_url() ); ?>" method="post"> |
32
|
|
|
|
33
|
|
|
<p><a href="#" class="shipping-calculator-button"><?php _e( 'Calculate Shipping', 'woocommerce' ); ?></a></p> |
34
|
|
|
|
35
|
|
|
<section class="shipping-calculator-form" style="display:none;"> |
36
|
|
|
|
37
|
|
|
<p class="form-row form-row-wide" id="calc_shipping_country_field"> |
38
|
|
|
<select name="calc_shipping_country" id="calc_shipping_country" class="country_to_state" rel="calc_shipping_state"> |
39
|
|
|
<option value=""><?php _e( 'Select a country…', 'woocommerce' ); ?></option> |
40
|
|
|
<?php |
41
|
|
|
foreach( WC()->countries->get_shipping_countries() as $key => $value ) |
42
|
|
|
echo '<option value="' . esc_attr( $key ) . '"' . selected( WC()->customer->get_shipping_country(), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>'; |
43
|
|
|
?> |
44
|
|
|
</select> |
45
|
|
|
</p> |
46
|
|
|
|
47
|
|
|
<p class="form-row form-row-wide" id="calc_shipping_state_field"> |
48
|
|
|
<?php |
49
|
|
|
$current_cc = WC()->customer->get_shipping_country(); |
50
|
|
|
$current_r = WC()->customer->get_shipping_state(); |
51
|
|
|
$states = WC()->countries->get_states( $current_cc ); |
52
|
|
|
|
53
|
|
|
// Hidden Input |
54
|
|
|
if ( is_array( $states ) && empty( $states ) ) { |
55
|
|
|
|
56
|
|
|
?><input type="hidden" name="calc_shipping_state" id="calc_shipping_state" placeholder="<?php esc_attr_e( 'State / county', 'woocommerce' ); ?>" /><?php |
57
|
|
|
|
58
|
|
|
// Dropdown Input |
59
|
|
|
} elseif ( is_array( $states ) ) { |
60
|
|
|
|
61
|
|
|
?><span> |
62
|
|
|
<select name="calc_shipping_state" id="calc_shipping_state" placeholder="<?php esc_attr_e( 'State / county', 'woocommerce' ); ?>"> |
63
|
|
|
<option value=""><?php _e( 'Select a state…', 'woocommerce' ); ?></option> |
64
|
|
|
<?php |
65
|
|
View Code Duplication |
foreach ( $states as $ckey => $cvalue ) |
|
|
|
|
66
|
|
|
echo '<option value="' . esc_attr( $ckey ) . '" ' . selected( $current_r, $ckey, false ) . '>' . __( esc_html( $cvalue ), 'woocommerce' ) .'</option>'; |
67
|
|
|
?> |
68
|
|
|
</select> |
69
|
|
|
</span><?php |
70
|
|
|
|
71
|
|
|
// Standard Input |
72
|
|
|
} else { |
73
|
|
|
|
74
|
|
|
?><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" /><?php |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
?> |
78
|
|
|
</p> |
79
|
|
|
|
80
|
|
View Code Duplication |
<?php if ( apply_filters( 'woocommerce_shipping_calculator_enable_city', false ) ) : ?> |
|
|
|
|
81
|
|
|
|
82
|
|
|
<p class="form-row form-row-wide" id="calc_shipping_city_field"> |
83
|
|
|
<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" /> |
84
|
|
|
</p> |
85
|
|
|
|
86
|
|
|
<?php endif; ?> |
87
|
|
|
|
88
|
|
View Code Duplication |
<?php if ( apply_filters( 'woocommerce_shipping_calculator_enable_postcode', true ) ) : ?> |
|
|
|
|
89
|
|
|
|
90
|
|
|
<p class="form-row form-row-wide" id="calc_shipping_postcode_field"> |
91
|
|
|
<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" /> |
92
|
|
|
</p> |
93
|
|
|
|
94
|
|
|
<?php endif; ?> |
95
|
|
|
|
96
|
|
|
<p><button type="submit" name="calc_shipping" value="1" class="button"><?php _e( 'Update Totals', 'woocommerce' ); ?></button></p> |
97
|
|
|
|
98
|
|
|
<?php wp_nonce_field( 'woocommerce-cart' ); ?> |
99
|
|
|
</section> |
100
|
|
|
</form> |
101
|
|
|
|
102
|
|
|
<?php do_action( 'woocommerce_after_shipping_calculator' ); ?> |
103
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.