City field on shipping calc
This commit is contained in:
parent
e981258d94
commit
6924817c22
|
@ -46,7 +46,8 @@ class WC_Shortcode_Cart {
|
|||
$woocommerce->customer->calculated_shipping( true );
|
||||
$country = $_POST['calc_shipping_country'];
|
||||
$state = $_POST['calc_shipping_state'];
|
||||
$postcode = $_POST['calc_shipping_postcode'];
|
||||
$postcode = apply_filters( 'woocommerce_shipping_calculator_enable_postcode', true ) ? stripslashes( $_POST['calc_shipping_postcode'] ) : '';
|
||||
$city = apply_filters( 'woocommerce_shipping_calculator_enable_city', false ) ? stripslashes( $_POST['calc_shipping_city'] ) : '';
|
||||
|
||||
if ( $postcode && ! $validation->is_postcode( $postcode, $country ) ) {
|
||||
$woocommerce->add_error( __( 'Please enter a valid postcode/ZIP.', 'woocommerce' ) );
|
||||
|
@ -58,8 +59,8 @@ class WC_Shortcode_Cart {
|
|||
if ( $country ) {
|
||||
|
||||
// Update customer location
|
||||
$woocommerce->customer->set_location( $country, $state, $postcode );
|
||||
$woocommerce->customer->set_shipping_location( $country, $state, $postcode );
|
||||
$woocommerce->customer->set_location( $country, $state, $postcode, $city );
|
||||
$woocommerce->customer->set_shipping_location( $country, $state, $postcode, $city );
|
||||
$woocommerce->add_message( __( 'Shipping costs updated.', 'woocommerce' ) );
|
||||
|
||||
} else {
|
||||
|
|
|
@ -165,6 +165,9 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
|
|||
|
||||
== Changelog ==
|
||||
|
||||
= X =
|
||||
* Tweak - Support for the city field in shipping calc (filterable)
|
||||
|
||||
= 2.0.7 - 12/04/2013 =
|
||||
* Feature - Option for GA _setDomainName.
|
||||
* Tweak - Removed rounding when option to round at subtotal is set.
|
||||
|
|
|
@ -4,71 +4,86 @@
|
|||
*
|
||||
* @author WooThemes
|
||||
* @package WooCommerce/Templates
|
||||
* @version 1.6.4
|
||||
* @version 2.0.8
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
global $woocommerce;
|
||||
|
||||
if ( get_option('woocommerce_enable_shipping_calc')=='no' || ! $woocommerce->cart->needs_shipping() ) return;
|
||||
if ( get_option('woocommerce_enable_shipping_calc')=='no' || ! $woocommerce->cart->needs_shipping() )
|
||||
return;
|
||||
?>
|
||||
|
||||
<?php do_action( 'woocommerce_before_shipping_calculator' ); ?>
|
||||
|
||||
<form class="shipping_calculator" action="<?php echo esc_url( $woocommerce->cart->get_cart_url() ); ?>" method="post">
|
||||
|
||||
<h2><a href="#" class="shipping-calculator-button"><?php _e( 'Calculate Shipping', 'woocommerce' ); ?> <span>↓</span></a></h2>
|
||||
|
||||
<section class="shipping-calculator-form">
|
||||
|
||||
<p class="form-row form-row-wide">
|
||||
<select name="calc_shipping_country" id="calc_shipping_country" class="country_to_state" rel="calc_shipping_state">
|
||||
<option value=""><?php _e( 'Select a country…', 'woocommerce' ); ?></option>
|
||||
<?php
|
||||
foreach( $woocommerce->countries->get_allowed_countries() as $key => $value )
|
||||
echo '<option value="' . $key . '"' . selected( $woocommerce->customer->get_shipping_country(), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
|
||||
echo '<option value="' . esc_attr( $key ) . '"' . selected( $woocommerce->customer->get_shipping_country(), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
|
||||
<p class="form-row form-row-wide">
|
||||
<?php
|
||||
$current_cc = $woocommerce->customer->get_shipping_country();
|
||||
$current_r = $woocommerce->customer->get_shipping_state();
|
||||
|
||||
$states = $woocommerce->countries->get_states( $current_cc );
|
||||
$current_r = $woocommerce->customer->get_shipping_state();
|
||||
$states = $woocommerce->countries->get_states( $current_cc );
|
||||
|
||||
// Hidden Input
|
||||
if ( is_array( $states ) && empty( $states ) ) {
|
||||
|
||||
// Hidden
|
||||
?>
|
||||
<input type="hidden" name="calc_shipping_state" id="calc_shipping_state" placeholder="<?php _e( 'State / county', 'woocommerce' ); ?>" />
|
||||
<?php
|
||||
?><input type="hidden" name="calc_shipping_state" id="calc_shipping_state" placeholder="<?php _e( 'State / county', 'woocommerce' ); ?>" /><?php
|
||||
|
||||
// Dropdown Input
|
||||
} elseif ( is_array( $states ) ) {
|
||||
|
||||
// Dropdown
|
||||
?>
|
||||
<span>
|
||||
<select name="calc_shipping_state" id="calc_shipping_state" placeholder="<?php _e( 'State / county', 'woocommerce' ); ?>"><option value=""><?php _e( 'Select a state…', 'woocommerce' ); ?></option><?php
|
||||
foreach ( $states as $ckey => $cvalue )
|
||||
echo '<option value="' . esc_attr( $ckey ) . '" '.selected( $current_r, $ckey, false ) .'>' . __( esc_html( $cvalue ), 'woocommerce' ) .'</option>';
|
||||
?></select>
|
||||
</span>
|
||||
<?php
|
||||
?><span>
|
||||
<select name="calc_shipping_state" id="calc_shipping_state" placeholder="<?php _e( 'State / county', 'woocommerce' ); ?>">
|
||||
<option value=""><?php _e( 'Select a state…', 'woocommerce' ); ?></option>
|
||||
<?php
|
||||
foreach ( $states as $ckey => $cvalue )
|
||||
echo '<option value="' . esc_attr( $ckey ) . '" ' . selected( $current_r, $ckey, false ) . '>' . __( esc_html( $cvalue ), 'woocommerce' ) .'</option>';
|
||||
?>
|
||||
</select>
|
||||
</span><?php
|
||||
|
||||
// Standard Input
|
||||
} else {
|
||||
|
||||
// Input
|
||||
?>
|
||||
<input type="text" class="input-text" value="<?php echo esc_attr( $current_r ); ?>" placeholder="<?php _e( 'State / county', 'woocommerce' ); ?>" name="calc_shipping_state" id="calc_shipping_state" />
|
||||
<?php
|
||||
?><input type="text" class="input-text" value="<?php echo esc_attr( $current_r ); ?>" placeholder="<?php _e( 'State / county', 'woocommerce' ); ?>" name="calc_shipping_state" id="calc_shipping_state" /><?php
|
||||
|
||||
}
|
||||
?>
|
||||
</p>
|
||||
<p class="form-row form-row-wide">
|
||||
<input type="text" class="input-text" value="<?php echo esc_attr( $woocommerce->customer->get_shipping_postcode() ); ?>" placeholder="<?php _e( 'Postcode / Zip', 'woocommerce' ); ?>" title="<?php _e( 'Postcode', 'woocommerce' ); ?>" name="calc_shipping_postcode" id="calc_shipping_postcode" />
|
||||
</p>
|
||||
<div class="clear"></div>
|
||||
|
||||
<?php if ( apply_filters( 'woocommerce_shipping_calculator_enable_city', false ) ) : ?>
|
||||
|
||||
<p class="form-row form-row-wide">
|
||||
<input type="text" class="input-text" value="<?php echo esc_attr( $woocommerce->customer->get_shipping_city() ); ?>" placeholder="<?php _e( 'City', 'woocommerce' ); ?>" name="calc_shipping_city" id="calc_shipping_city" />
|
||||
</p>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( apply_filters( 'woocommerce_shipping_calculator_enable_postcode', true ) ) : ?>
|
||||
|
||||
<p class="form-row form-row-wide">
|
||||
<input type="text" class="input-text" value="<?php echo esc_attr( $woocommerce->customer->get_shipping_postcode() ); ?>" placeholder="<?php _e( 'Postcode / Zip', 'woocommerce' ); ?>" name="calc_shipping_postcode" id="calc_shipping_postcode" />
|
||||
</p>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<p><button type="submit" name="calc_shipping" value="1" class="button"><?php _e( 'Update Totals', 'woocommerce' ); ?></button></p>
|
||||
|
||||
<?php $woocommerce->nonce_field('cart') ?>
|
||||
</section>
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue