Skip to content

Instantly share code, notes, and snippets.

@loxK
Created March 10, 2011 01:12
Show Gist options
  • Save loxK/863384 to your computer and use it in GitHub Desktop.
Save loxK/863384 to your computer and use it in GitHub Desktop.
Better wp-ecommerce regitration process: register then checkout
Index: wpsc-includes/misc.functions.php
===================================================================
--- wpsc-includes/misc.functions.php (révision 357938)
+++ wpsc-includes/misc.functions.php (copie de travail)
@@ -92,6 +92,7 @@
}
$credentials = array( 'user_login' => $user_login, 'user_password' => $user_pass, 'remember' => true );
$user = wp_signon( $credentials );
+ wp_set_current_user($user->ID);
return $user;
//wp_new_user_notification($user_id, $user_pass);
Index: wpsc-includes/checkout.class.php
===================================================================
--- wpsc-includes/checkout.class.php (révision 357938)
+++ wpsc-includes/checkout.class.php (copie de travail)
@@ -698,6 +698,12 @@
case "email":
case "coupon":
default:
+
+ // if no email registred, uses current connected user email
+ if ( $this->checkout_item->type === "email" && !$saved_form_data && is_user_logged_in() ) {
+ $saved_form_data = wp_get_current_user()->user_email;
+ }
+
if ( $this->checkout_item->unique_name == 'shippingstate' ) {
if ( wpsc_uses_shipping() && wpsc_has_regions($_SESSION['wpsc_delivery_country']) ) {
$region_name = $wpdb->get_var( "SELECT `name` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `id`='" . $_SESSION['wpsc_delivery_region'] . "' LIMIT 1" );
@@ -734,6 +740,8 @@
global $wpdb, $current_user, $user_ID;
$any_bad_inputs = false;
$bad_input_message = '';
+ $is_registration = ( isset( $_POST['log'] ) || isset( $_POST['pwd'] ) || isset( $_POST['user_email'] ) ) ? true : false;
+
// Credit Card Number Validation for PayPal Pro and maybe others soon
if ( isset( $_POST['card_number'] ) ) {
//should do some php CC validation here~
@@ -781,7 +789,7 @@
$_SESSION['wpsc_gateway_error_messages']['cctype'] = '';
}
}
- if ( isset( $_POST['log'] ) || isset( $_POST['pwd'] ) || isset( $_POST['user_email'] ) ) {
+ if ( $is_registration ) {
$results = wpsc_add_new_user( $_POST['log'], $_POST['pwd'], $_POST['user_email'] );
$_SESSION['wpsc_checkout_user_error_messages'] = array( );
if ( is_callable( array( $results, "get_error_code" ) ) && $results->get_error_code() ) {
@@ -808,42 +816,44 @@
$user_ID = $our_user_id;
}
//Basic Form field validation for billing and shipping details
- foreach ( $this->checkout_items as $form_data ) {
- $value = '';
- if( isset( $_POST['collected_data'][$form_data->id] ) )
- $value = $_POST['collected_data'][$form_data->id];
- $_SESSION['wpsc_checkout_saved_values'][$form_data->id] = $value;
- $bad_input = false;
- if ( ($form_data->mandatory == 1) || ($form_data->type == "coupon") ) {
- switch ( $form_data->type ) {
- case "email":
- if ( !preg_match( "/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-.]+\.[a-zA-Z]{2,5}$/", $value ) ) {
- $any_bad_inputs = true;
- $bad_input = true;
- }
- break;
-
- case "delivery_country":
- case "country":
- case "heading":
- break;
- case "select":
- if ( $value == '-1' ) {
- $any_bad_inputs = true;
- $bad_input = true;
- }
- break;
- default:
- if ( $value == null ) {
- $any_bad_inputs = true;
- $bad_input = true;
- }
- break;
+ if( !$is_registration ) {
+ foreach ( $this->checkout_items as $form_data ) {
+ $value = '';
+ if( isset( $_POST['collected_data'][$form_data->id] ) )
+ $value = $_POST['collected_data'][$form_data->id];
+ $_SESSION['wpsc_checkout_saved_values'][$form_data->id] = $value;
+ $bad_input = false;
+ if ( ($form_data->mandatory == 1) || ($form_data->type == "coupon") ) {
+ switch ( $form_data->type ) {
+ case "email":
+ if ( !preg_match( "/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-.]+\.[a-zA-Z]{2,5}$/", $value ) ) {
+ $any_bad_inputs = true;
+ $bad_input = true;
+ }
+ break;
+
+ case "delivery_country":
+ case "country":
+ case "heading":
+ break;
+ case "select":
+ if ( $value == '-1' ) {
+ $any_bad_inputs = true;
+ $bad_input = true;
+ }
+ break;
+ default:
+ if ( $value == null ) {
+ $any_bad_inputs = true;
+ $bad_input = true;
+ }
+ break;
+ }
+ if ( $bad_input === true ) {
+ $_SESSION['wpsc_checkout_error_messages'][$form_data->id] = sprintf(__( 'Please enter a valid <span class="wpsc_error_msg_field_name">%s</span>.', 'wpsc' ), esc_attr($form_data->name) );
+ $_SESSION['wpsc_checkout_saved_values'][$form_data->id] = '';
+ }
}
- if ( $bad_input === true ) {
- $_SESSION['wpsc_checkout_error_messages'][$form_data->id] = sprintf(__( 'Please enter a valid <span class="wpsc_error_msg_field_name">%s</span>.', 'wpsc' ), esc_attr($form_data->name) );
- $_SESSION['wpsc_checkout_saved_values'][$form_data->id] = '';
- }
}
}
Index: wpsc-theme/wpsc-shopping_cart_page.php
===================================================================
--- wpsc-theme/wpsc-shopping_cart_page.php (révision 357938)
+++ wpsc-theme/wpsc-shopping_cart_page.php (copie de travail)
@@ -217,7 +217,7 @@
?>
<?php endif; ?>
- <?php if ( wpsc_show_user_login_form() && !is_user_logged_in() ): ?>
+ <?php if ( wpsc_show_user_login_form() ): ?>
<p><?php _e('You must sign in or register with us to continue with your purchase', 'wpsc');?></p>
<div class="wpsc_registration_form">
@@ -258,12 +258,18 @@
<label><?php _e('E-mail', 'wpsc'); ?>:</label>
<input type="text" name="user_email" id="user_email" value="<?php echo attribute_escape(stripslashes($user_email)); ?>" size="20" /><br />
+ <input type='hidden' value='submit_checkout' name='wpsc_action' />
+ <input type='hidden' value='yes' name='agree' />
+ <input type='submit' value='<?php _e('Register', 'wpsc');?>' name='submit' class='register wpsc_register_button' />
+
<div class="wpsc_signup_text"><?php _e('Signing up is free and easy! please fill out your details your registration will happen automatically as you checkout. Don\'t forget to use your details to login with next time!', 'wpsc');?></div>
</fieldset>
</div>
<div class="clear"></div>
- <?php endif; // closes user login form
+ </form>
+
+ <?php else: // closes user login form
if(!empty($_SESSION['wpsc_checkout_misc_error_messages'])): ?>
<div class='login_error'>
@@ -500,6 +506,7 @@
<div class='clear'></div>
</form>
+<?php endif; ?>
</div>
</div><!--close checkout_page_container-->
<?php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment