2011-08-10 17:11:11 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Cart Shortcode
|
|
|
|
*
|
|
|
|
* Used on the cart page, the cart shortcode displays the cart contents and interface for coupon codes and other cart bits and pieces.
|
|
|
|
*
|
|
|
|
* @package WooCommerce
|
|
|
|
* @category Shortcode
|
|
|
|
* @author WooThemes
|
|
|
|
*/
|
|
|
|
|
|
|
|
function get_woocommerce_cart( $atts ) {
|
2011-09-06 11:11:22 +00:00
|
|
|
global $woocommerce;
|
|
|
|
return $woocommerce->shortcode_wrapper('woocommerce_cart', $atts);
|
2011-08-10 17:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function woocommerce_cart( $atts ) {
|
2011-09-06 11:11:22 +00:00
|
|
|
global $woocommerce;
|
2011-08-10 17:11:11 +00:00
|
|
|
|
2011-12-09 17:01:56 +00:00
|
|
|
// Remove Discount Codes
|
2012-01-02 12:48:56 +00:00
|
|
|
if (isset($_GET['remove_discounts'])) :
|
2011-11-21 11:33:46 +00:00
|
|
|
|
2011-11-21 17:11:44 +00:00
|
|
|
$woocommerce->cart->remove_coupons( $_GET['remove_discounts'] );
|
2011-11-21 11:33:46 +00:00
|
|
|
$woocommerce->cart->calculate_totals();
|
|
|
|
|
2011-08-10 17:11:11 +00:00
|
|
|
// Update Shipping
|
2011-09-06 11:11:22 +00:00
|
|
|
elseif (isset($_POST['calc_shipping']) && $_POST['calc_shipping'] && $woocommerce->verify_nonce('cart')) :
|
2011-10-31 16:27:41 +00:00
|
|
|
|
2012-01-13 00:46:56 +00:00
|
|
|
$validation = $woocommerce->validation();
|
|
|
|
|
2011-10-31 16:27:41 +00:00
|
|
|
$_SESSION['calculated_shipping'] = true;
|
2011-09-02 14:42:04 +00:00
|
|
|
unset($_SESSION['_chosen_shipping_method']);
|
2011-08-10 17:11:11 +00:00
|
|
|
$country = $_POST['calc_shipping_country'];
|
|
|
|
$state = $_POST['calc_shipping_state'];
|
|
|
|
$postcode = $_POST['calc_shipping_postcode'];
|
|
|
|
|
2012-01-13 00:46:56 +00:00
|
|
|
if ($postcode && !$validation->is_postcode( $postcode, $country )) :
|
2012-01-05 11:31:22 +00:00
|
|
|
$woocommerce->add_error( __('Please enter a valid postcode/ZIP.', 'woocommerce') );
|
2011-08-10 17:11:11 +00:00
|
|
|
$postcode = '';
|
|
|
|
elseif ($postcode) :
|
2012-01-13 00:46:56 +00:00
|
|
|
$postcode = $validation->format_postcode( $postcode, $country );
|
2011-08-10 17:11:11 +00:00
|
|
|
endif;
|
|
|
|
|
|
|
|
if ($country) :
|
|
|
|
|
|
|
|
// Update customer location
|
2011-09-06 11:11:22 +00:00
|
|
|
$woocommerce->customer->set_location( $country, $state, $postcode );
|
|
|
|
$woocommerce->customer->set_shipping_location( $country, $state, $postcode );
|
|
|
|
$woocommerce->cart->calculate_totals();
|
2012-01-05 11:31:22 +00:00
|
|
|
$woocommerce->add_message( __('Shipping costs updated.', 'woocommerce') );
|
2011-08-10 17:11:11 +00:00
|
|
|
|
|
|
|
else :
|
|
|
|
|
2011-12-14 23:50:32 +00:00
|
|
|
$woocommerce->customer->set_shipping_to_base();
|
2012-01-05 11:31:22 +00:00
|
|
|
$woocommerce->add_message( __('Shipping costs updated.', 'woocommerce') );
|
2011-08-10 17:11:11 +00:00
|
|
|
|
|
|
|
endif;
|
2011-11-21 11:33:46 +00:00
|
|
|
|
2011-08-10 17:11:11 +00:00
|
|
|
endif;
|
|
|
|
|
2011-11-09 17:26:45 +00:00
|
|
|
do_action('woocommerce_check_cart_items');
|
2011-08-10 17:11:11 +00:00
|
|
|
|
2011-11-06 13:45:18 +00:00
|
|
|
if (sizeof($woocommerce->cart->get_cart())==0) :
|
2011-09-11 16:42:50 +00:00
|
|
|
|
2011-12-09 17:01:56 +00:00
|
|
|
woocommerce_get_template( 'cart/empty.php' );
|
|
|
|
|
|
|
|
else :
|
|
|
|
|
|
|
|
woocommerce_get_template( 'cart/cart.php' );
|
2011-08-10 17:11:11 +00:00
|
|
|
|
2011-12-09 17:01:56 +00:00
|
|
|
endif;
|
2011-08-10 17:11:11 +00:00
|
|
|
}
|