show_shipping. Closes #901.

This commit is contained in:
Mike Jolley 2012-04-11 13:08:04 +01:00
parent d3893c10f4
commit b9bec0be75
9 changed files with 41 additions and 15 deletions

View File

@ -853,8 +853,8 @@ $woocommerce_settings['shipping'] = apply_filters('woocommerce_shipping_settings
array(
'name' => __( 'Shipping calculations', 'woocommerce' ),
'desc' => __( 'Hide shipping costs until address is entered', 'woocommerce' ),
'id' => 'woocommerce_hide_shipping_address',
'desc' => __( 'Hide shipping costs until an address is entered', 'woocommerce' ),
'id' => 'woocommerce_shipping_cost_requires_address',
'std' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end'

View File

@ -1327,7 +1327,7 @@ class WC_Cart {
function calculate_shipping() {
global $woocommerce;
if ( $this->needs_shipping() ) {
if ( $this->needs_shipping() && $this->show_shipping() ) {
$woocommerce->shipping->calculate_shipping();
} else {
$woocommerce->shipping->reset_shipping();
@ -1360,6 +1360,31 @@ class WC_Cart {
return apply_filters( 'woocomerce_cart_needs_shipping', $needs_shipping );
}
/**
* show_shipping
*
* Sees if the customer has entered enough data to calc the shipping yet
*
* @return bool
*/
function show_shipping() {
global $woocommerce;
if ( get_option('woocommerce_calc_shipping')=='no' ) return false;
if ( ! is_array( $this->cart_contents ) ) return false;
if ( get_option( 'woocommerce_shipping_cost_requires_address' ) == 'yes' ) {
if ( empty( $_SESSION['calculated_shipping'] ) ) {
if ( ! $woocommerce->customer->get_shipping_country() || ! $woocommerce->customer->get_shipping_state() ) return false;
}
}
$show_shipping = true;
return apply_filters( 'woocomerce_cart_ready_to_calc_shipping', $show_shipping );
}
/**
* Sees if we need a shipping address
*

View File

@ -26,10 +26,10 @@ class WC_Customer {
endif;
$data = array(
'country' => $country,
'state' => $state,
'state' => '',
'postcode' => '',
'shipping_country' => $country,
'shipping_state' => $state,
'shipping_state' => '',
'shipping_postcode' => '',
'is_vat_exempt' => false
);

View File

@ -148,6 +148,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Feature - Allow external products to be a part of a grouped product. Button titles will be respected when displayed.
* Feature - Added woocommerce_get_dimension/woocommerce_get_weight helpers for normalisation. Thanks Andy Zhang
* Feature - Pass page_style to paypal standard if defined
* Feature - Option to hide shipping costs until an address is entered on the cart/checkout
* Tweak - Show multiple success messages/error messages if added, rather than one or the other
* Tweak - Adding an item to an order now uses the ajax style product finder
* Tweak - Updated chosen to latest release

View File

@ -5,7 +5,7 @@
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' ); ?>
@ -47,7 +47,7 @@ if (get_option('woocommerce_enable_shipping_calc')=='no' || !$woocommerce->cart-
else :
// Input
?>
<input type="text" class="input-text" value="<?php echo esc_attr( $current_r ); ?>" placeholder="<?php _e('state', 'woocommerce'); ?>" name="calc_shipping_state" id="calc_shipping_state" />
<input type="text" class="input-text" value="<?php echo esc_attr( $current_r ); ?>" placeholder="<?php _e('State', 'woocommerce'); ?>" name="calc_shipping_state" id="calc_shipping_state" />
<?php
endif;
?>

View File

@ -7,11 +7,11 @@ global $woocommerce;
$available_methods = $woocommerce->shipping->get_available_shipping_methods();
?>
<div class="cart_totals <?php if (isset($_SESSION['calculated_shipping']) && $_SESSION['calculated_shipping']) echo 'calculated_shipping'; ?>">
<div class="cart_totals <?php if ( isset( $_SESSION['calculated_shipping'] ) && $_SESSION['calculated_shipping'] ) echo 'calculated_shipping'; ?>">
<?php do_action('woocommerce_before_cart_totals'); ?>
<?php if ( !$woocommerce->shipping->enabled || $available_methods || !$woocommerce->customer->get_shipping_country() || !isset($_SESSION['calculated_shipping']) || !$_SESSION['calculated_shipping'] ) : ?>
<?php if ( ! $woocommerce->shipping->enabled || $available_methods || ! $woocommerce->customer->get_shipping_country() || empty( $_SESSION['calculated_shipping'] ) ) : ?>
<h2><?php _e('Cart Totals', 'woocommerce'); ?></h2>
<table cellspacing="0" cellpadding="0">
@ -31,7 +31,7 @@ $available_methods = $woocommerce->shipping->get_available_shipping_methods();
<?php endif; ?>
<?php if ( $woocommerce->cart->needs_shipping() && ( $available_methods || get_option( 'woocommerce_enable_shipping_calc' ) == 'yes' ) && get_option( 'woocommerce_hide_shipping_address' ) != 'yes' ) { ?>
<?php if ( $woocommerce->cart->needs_shipping() && $woocommerce->cart->show_shipping() && ( $available_methods || get_option( 'woocommerce_enable_shipping_calc' ) == 'yes' ) ) { ?>
<tr class="shipping">
<th><?php _e('Shipping', 'woocommerce'); ?></th>
@ -201,7 +201,7 @@ $available_methods = $woocommerce->shipping->get_available_shipping_methods();
<?php else : ?>
<?php if (!$woocommerce->customer->get_shipping_state() || !$woocommerce->customer->get_shipping_postcode()) : ?>
<?php if ( ! $woocommerce->customer->get_shipping_state() || ! $woocommerce->customer->get_shipping_postcode() ) : ?>
<div class="woocommerce_info">
<p><?php _e('No shipping methods were found; please recalculate your shipping and enter your state/county and zip/postcode to ensure their are no other available methods for your location.', 'woocommerce'); ?></p>

View File

@ -5,7 +5,7 @@
global $woocommerce;
?>
<?php if ($woocommerce->cart->needs_shipping() && !$woocommerce->cart->ship_to_billing_address_only()) : ?>
<?php if ( $woocommerce->cart->needs_shipping() && ! $woocommerce->cart->ship_to_billing_address_only() ) : ?>
<?php
if (!isset($_POST) || !$_POST) :

View File

@ -33,7 +33,7 @@ $available_methods = $woocommerce->shipping->get_available_shipping_methods();
<?php endif; ?>
<?php if ($woocommerce->cart->needs_shipping()) : ?>
<?php if ( $woocommerce->cart->needs_shipping() && $woocommerce->cart->show_shipping() ) : ?>
<?php do_action('woocommerce_review_order_before_shipping'); ?>

View File

@ -80,9 +80,9 @@ function woocommerce_ajax_update_shipping_method() {
check_ajax_referer( 'update-shipping-method', 'security' );
if (!defined('WOOCOMMERCE_CART')) define('WOOCOMMERCE_CART', true);
if ( ! defined('WOOCOMMERCE_CART') ) define( 'WOOCOMMERCE_CART', true );
if (isset($_POST['shipping_method'])) $_SESSION['_chosen_shipping_method'] = $_POST['shipping_method'];
if ( isset( $_POST['shipping_method'] ) ) $_SESSION['_chosen_shipping_method'] = $_POST['shipping_method'];
$woocommerce->cart->calculate_totals();