form-checkout.php
6.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* Checkout Form
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
wc_print_notices();
do_action( 'woocommerce_before_checkout_form', $checkout );
// If checkout registration is disabled and not logged in, the user cannot checkout
if ( ! $checkout->enable_signup && ! $checkout->enable_guest_checkout && ! is_user_logged_in() ) {
echo apply_filters( 'woocommerce_checkout_must_be_logged_in_message', __( 'You must be logged in to checkout.', 'woocommerce' ) );
return;
}
if (is_user_logged_in()) { $current_user = wp_get_current_user(); }
// filter hook for include new pages inside the payment method
$get_checkout_url = apply_filters( 'woocommerce_get_checkout_url', WC()->cart->get_checkout_url() ); ?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(".default").each(function(){
var defaultVal = jQuery(this).attr('title');
jQuery(this).focus(function(){
if (jQuery(this).val() == defaultVal){
jQuery(this).removeClass('active').val('');
}
});
jQuery(this).blur(function() {
if (jQuery(this).val() == ''){
jQuery(this).addClass('active').val(defaultVal);
}
})
.blur().addClass('active');
});
jQuery('.rc-submit').click(function(e){
var jQueryformId = jQuery(this).parents('form');
defaulttextRemove();
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
jQuery('p',jQueryformId).removeClass('error');
jQuery('span.error').remove();
jQuery('.rc_required',jQueryformId).each(function(){
var inputVal = jQuery(this).val();
var jQueryparentTag = jQuery(this).parent();
if(inputVal == ''){
jQueryparentTag.addClass('error').append('<span class="error">Required field</span>');
}
if(jQuery(this).hasClass('email') == true){
if(!emailReg.test(inputVal)){
jQueryparentTag.addClass('error').append('<span class="error">Enter a valid email address.</span>');
}
}
});
if (jQuery('span.error').length == "0") {
jQueryformId.css("opacity",".5");
jQuery('fieldset',jQueryformId).hide();
var fname = jQuery('#input-fname').val();
var lname = jQuery('#input-lname').val();
var email = jQuery('#input-email').val();
updateAC(fname,lname,email);
}
e.preventDefault();
});
});
function defaulttextRemove(){
jQuery('.default').each(function(){
var defaultVal = jQuery(this).attr('title');
if (jQuery(this).val() == defaultVal){
jQuery(this).val('');
}
});
}
function updateAC(fname,lname,email){
jQuery.ajax({
url: '<?php echo admin_url('admin-ajax.php'); ?>',
cache: false,
data: {
'action': 'aw_rc',
'fname' : fname,
'lname' : lname,
'email' : email
},
success: function(text) {
console.log(text);
jQuery('.awrc_recover-cart').replaceWith(text);
jQuery("#billing_first_name").val(fname);
jQuery("#billing_last_name").val(lname);
jQuery("#billing_email").val(email);
jQuery('#billing_phone_field').css({"width":"100%"});
jQuery("#billing_first_name_field, #billing_last_name_field,#billing_email_field").addClass('awrc_fake-hide');
jQuery('.awrc_show').show();
//if success then hide the first step, and show the rest of the check out fields.
}
});
}
</script>
<style>
.recover-cart span.error {font-size: 11px; display: block; padding: 2px;}
.recover-cart p.error {color: #D8000C; background: #fff0f0; border: 1px solid #f9c7c7; padding: 5px 2px;}
.recover-cartfieldset p.error label {text-align: left;}
.aw_rc-fake-hide, .awrc_fake-hide *, p.awrc_fake-hide, .awrc_fake-hide > input {text-indent: -9999px !important; height: 0px !important; width: 0px!important; float: none !important; color: transparent !important; border: none !important; display: inline-block !important; margin: 0px !important; padding: 0px !important;} </style>
<div class="awrc_recover-cart">
<h3>Contact Info:</h3>
<form>
<div style="width:100%; float:left">
<p class="form-row form-row form-row-first validate-required default" id="billing_first_name_field"><label for="billing_first_name" class="">First Name <abbr class="required" title="required">*</abbr></label><input type="text" class="input-text rc_required" name="input-fname" id="input-fname" placeholder="" value="<?php if ($current_user->user_firstname){ echo $current_user->user_firstname;}?>" style="cursor: auto;"></p>
<p class="form-row form-row form-row-last validate-required default" id="billing_last_name_field"><label for="billing_last_name" class="">Last Name <abbr class="required" title="required">*</abbr></label><input type="text" class="input-text rc_required" name="input-lname" id="input-lname" placeholder="" value="<?php if ($current_user->user_lastname){ echo $current_user->user_lastname;}?>"></p>
</div>
<p class="form-row form-row-wide validate-required validate-email default" id="billing_email_field"><label for="billing_email" class="">Email Address <abbr class="required" title="required">*</abbr></label><input type="email" class="input-text rc_required email" name="billing_email" id="input-email" placeholder="" value="<?php if ($current_user->user_email){ echo $current_user->user_email;}?>"></p>
<div class="woocommerce">
<button type="submit" class="checkout-button button alt wc-forward rc-submit" style="width:50%; margin-left:25%">NEXT</button>
</div>
</form>
<h3 class="awrc_billing_details" style="border-bottom: 1px solid gray; padding-bottom: 20px">Billing Details</h3>
<h3>Confirm Order</h3>
</div>
<div class="awrc_show" style="display:none;">
<form name="checkout" method="post" class="checkout woocommerce-checkout" action="<?php echo esc_url( $get_checkout_url ); ?>" enctype="multipart/form-data">
<?php if ( sizeof( $checkout->checkout_fields ) > 0 ) : ?>
<?php do_action( 'woocommerce_checkout_before_customer_details' ); ?>
<div class="col2-set" id="customer_details">
<div style="float:left; width: 95%">
<?php do_action( 'woocommerce_checkout_billing' ); ?>
</div>
<div style="float:left; width: 95%">
<?php do_action( 'woocommerce_checkout_shipping' ); ?>
</div>
</div>
<?php do_action( 'woocommerce_checkout_after_customer_details' ); ?>
<h3 id="order_review_heading"><?php _e( 'Your order', 'woocommerce' ); ?></h3>
<?php endif; ?>
<?php do_action( 'woocommerce_checkout_before_order_review' ); ?>
<div id="order_review" class="woocommerce-checkout-review-order">
<?php do_action( 'woocommerce_checkout_order_review' ); ?>
</div>
<?php do_action( 'woocommerce_checkout_after_order_review' ); ?>
</form>
</div>
<?php do_action( 'woocommerce_after_checkout_form', $checkout ); ?>