Coupon on checkout. Closes #379.
This commit is contained in:
parent
c04b45addd
commit
c4625ad91e
|
@ -106,6 +106,14 @@ $woocommerce_settings['general'] = apply_filters('woocommerce_general_settings',
|
|||
'type' => 'checkbox',
|
||||
'checkboxgroup' => ''
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Enable coupon form on checkout', 'woothemes' ),
|
||||
'id' => 'woocommerce_enable_coupon_form_on_checkout',
|
||||
'std' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => ''
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( '"Ship to same address option" checked by default', 'woothemes' ),
|
||||
|
|
|
@ -490,7 +490,7 @@ jQuery(document).ready(function($) {
|
|||
|
||||
}
|
||||
|
||||
$('p.password, form.login, div.shipping_address').hide();
|
||||
$('p.password, form.login, form.checkout_coupon, div.shipping_address').hide();
|
||||
|
||||
$('input.show_password').change(function(){
|
||||
$('p.password').slideToggle();
|
||||
|
@ -501,6 +501,11 @@ jQuery(document).ready(function($) {
|
|||
return false;
|
||||
});
|
||||
|
||||
$('a.showcoupon').click(function(){
|
||||
$('form.checkout_coupon').slideToggle();
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#shiptobilling input').change(function(){
|
||||
$('div.shipping_address').hide();
|
||||
if (!$(this).is(':checked')) {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -255,7 +255,7 @@ class woocommerce_checkout {
|
|||
|
||||
do_action('woocommerce_before_checkout_process');
|
||||
|
||||
if (isset($_POST) && $_POST && !isset($_POST['login'])) :
|
||||
if (isset($_POST) && $_POST && !isset($_POST['login']) && !isset($_POST['coupon_code'])) :
|
||||
|
||||
$woocommerce->verify_nonce('process_checkout');
|
||||
|
||||
|
|
|
@ -97,6 +97,7 @@ Yes you can! Join in on our GitHub repository :) https://github.com/woothemes/wo
|
|||
* Option to hide cart widget if the cart is empty
|
||||
* Category widget - order by option
|
||||
* Option to re-order shipping methods
|
||||
* Coupon entry form on checkout (optional)
|
||||
|
||||
= 1.3.2.1 - 15/12/2011 =
|
||||
* Category/Ordering fix
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
* Checkout Coupon Form
|
||||
*/
|
||||
if (get_option('woocommerce_enable_coupon_form_on_checkout')=="no") return;
|
||||
|
||||
$info_message = apply_filters('woocommerce_checkout_coupon_message', __('Have a coupon?', 'woothemes'));
|
||||
?>
|
||||
|
||||
<p class="info"><?php echo $info_message; ?> <a href="#" class="showcoupon"><?php _e('Click here to enter your code', 'woothemes'); ?></a></p>
|
||||
|
||||
<form class="checkout_coupon" method="post">
|
||||
|
||||
<p class="form-row form-row-first">
|
||||
<input name="coupon_code" class="input-text" placeholder="<?php _e('Coupon code', 'woothemes'); ?>" id="coupon_code" value="" />
|
||||
</p>
|
||||
|
||||
<p class="form-row form-row-last">
|
||||
<input type="submit" class="button" name="apply_coupon" value="<?php _e('Apply Coupon', 'woothemes'); ?>" />
|
||||
</p>
|
||||
|
||||
<div class="clear"></div>
|
||||
</form>
|
|
@ -1,6 +1,8 @@
|
|||
<?php do_action('woocommerce_before_checkout_form');
|
||||
<?php global $woocommerce; ?>
|
||||
|
||||
global $woocommerce;
|
||||
<?php $woocommerce->show_messages(); ?>
|
||||
|
||||
<?php do_action('woocommerce_before_checkout_form');
|
||||
|
||||
// If checkout registration is disabled and not logged in, the user cannot checkout
|
||||
if (get_option('woocommerce_enable_signup_and_login_from_checkout')=="no" && get_option('woocommerce_enable_guest_checkout')=="no" && !is_user_logged_in()) :
|
||||
|
|
|
@ -24,4 +24,6 @@ if (is_user_logged_in()) return;
|
|||
<input type="submit" class="button" name="login" value="<?php _e('Login', 'woothemes'); ?>" />
|
||||
<a class="lost_password" href="<?php echo esc_url( wp_lostpassword_url( home_url() ) ); ?>"><?php _e('Lost Password?', 'woothemes'); ?></a>
|
||||
</p>
|
||||
|
||||
<div class="clear"></div>
|
||||
</form>
|
|
@ -421,6 +421,25 @@ function woocommerce_process_login() {
|
|||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the coupon form on the checkout
|
||||
**/
|
||||
function woocommerce_process_coupon_form() {
|
||||
global $woocommerce;
|
||||
|
||||
if (isset($_POST['coupon_code']) && $_POST['coupon_code']) :
|
||||
|
||||
$coupon_code = stripslashes(trim($_POST['coupon_code']));
|
||||
$woocommerce->cart->add_discount($coupon_code);
|
||||
|
||||
if ( wp_get_referer() ) :
|
||||
wp_safe_redirect( wp_get_referer() );
|
||||
exit;
|
||||
endif;
|
||||
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the registration form
|
||||
**/
|
||||
|
|
|
@ -80,6 +80,7 @@ add_action( 'woocommerce_product_tab_panels', 'woocommerce_product_reviews_panel
|
|||
|
||||
/* Checkout */
|
||||
add_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form', 10 );
|
||||
add_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
|
||||
add_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
|
||||
|
||||
/* Cart */
|
||||
|
@ -119,6 +120,7 @@ add_action( 'init', 'woocommerce_add_to_cart_action' );
|
|||
|
||||
/* Login and Registration */
|
||||
add_action( 'init', 'woocommerce_process_login' );
|
||||
add_action( 'init', 'woocommerce_process_coupon_form' );
|
||||
add_action( 'init', 'woocommerce_process_registration' );
|
||||
|
||||
/* Product Downloads */
|
||||
|
|
|
@ -431,6 +431,15 @@ if (!function_exists('woocommerce_order_review')) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Coupon form for checkout
|
||||
**/
|
||||
if (!function_exists('woocommerce_checkout_coupon_form')) {
|
||||
function woocommerce_checkout_coupon_form() {
|
||||
woocommerce_get_template('checkout/coupon-form.php', false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* display product sub categories as thumbnails
|
||||
**/
|
||||
|
|
Loading…
Reference in New Issue