Github sabotages files -.-
This commit is contained in:
parent
731878a8c4
commit
a2d51aa201
|
@ -753,12 +753,12 @@ function woocommerce_product_type_box() {
|
|||
), $product_type) ) );
|
||||
|
||||
// Visibility
|
||||
woocommerce_wp_select( array( 'id' => '_visibility', 'label' => __('Product visibility', 'woocommerce'), 'options' => apply_filters('woocommerce_product_visibility_options', array(
|
||||
'visible' => __('Catalog & Search', 'woocommerce'),
|
||||
woocommerce_wp_select( array( 'id' => '_visibility', 'label' => __('Visibility', 'woocommerce'), 'options' => apply_filters('woocommerce_product_visibility_options', array(
|
||||
'visible' => __('Catalog & search', 'woocommerce'),
|
||||
'catalog' => __('Catalog', 'woocommerce'),
|
||||
'search' => __('Search', 'woocommerce'),
|
||||
'hidden' => __('Hidden', 'woocommerce')
|
||||
)) ) );
|
||||
)), 'description' => __('Define the loops this product should be visible in. It will still be accessible directly.', 'woocommerce') ) );
|
||||
|
||||
woocommerce_wp_checkbox( array( 'id' => '_virtual', 'wrapper_class' => 'show_if_simple', 'label' => __('Virtual', 'woocommerce'), 'description' => __('Enable this option if a product is not shipped or there is no shipping cost', 'woocommerce') ) );
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@ add_action('admin_init', 'woocommerce_admin_init');
|
|||
function woocommerce_admin_init() {
|
||||
global $pagenow;
|
||||
|
||||
ob_start();
|
||||
|
||||
include_once( 'woocommerce-admin-hooks.php' );
|
||||
include_once( 'woocommerce-admin-functions.php' );
|
||||
|
||||
|
|
|
@ -157,322 +157,345 @@ class woocommerce_checkout {
|
|||
*/
|
||||
function process_checkout() {
|
||||
global $wpdb, $woocommerce;
|
||||
|
||||
|
||||
if (!defined('WOOCOMMERCE_CHECKOUT')) define('WOOCOMMERCE_CHECKOUT', true);
|
||||
|
||||
do_action('woocommerce_before_checkout_process');
|
||||
|
||||
if (isset($_POST) && $_POST && !isset($_POST['login']) && !isset($_POST['coupon_code'])) :
|
||||
$woocommerce->verify_nonce('process_checkout');
|
||||
|
||||
do_action('woocommerce_before_checkout_process');
|
||||
|
||||
$woocommerce->verify_nonce('process_checkout');
|
||||
if (sizeof($woocommerce->cart->get_cart())==0) :
|
||||
$woocommerce->add_error( sprintf(__('Sorry, your session has expired. <a href="%s">Return to homepage →</a>', 'woocommerce'), home_url()) );
|
||||
endif;
|
||||
|
||||
do_action('woocommerce_checkout_process');
|
||||
|
||||
if (sizeof($woocommerce->cart->get_cart())==0) :
|
||||
$woocommerce->add_error( sprintf(__('Sorry, your session has expired. <a href="%s">Return to homepage →</a>', 'woocommerce'), home_url()) );
|
||||
// Checkout fields (not defined in checkout_fields)
|
||||
$this->posted['shiptobilling'] = isset($_POST['shiptobilling']) ? 1 : 0;
|
||||
$this->posted['terms'] = isset($_POST['terms']) ? 1 : 0;
|
||||
$this->posted['createaccount'] = isset($_POST['createaccount']) ? 1 : 0;
|
||||
$this->posted['payment_method'] = isset($_POST['payment_method']) ? woocommerce_clean($_POST['payment_method']) : '';
|
||||
$this->posted['shipping_method'] = isset($_POST['shipping_method']) ? woocommerce_clean($_POST['shipping_method']) : '';
|
||||
|
||||
// Ship to billing only option
|
||||
if ($woocommerce->cart->ship_to_billing_address_only()) $this->posted['shiptobilling'] = 1;
|
||||
|
||||
// Update customer shipping and payment method to posted method
|
||||
$_SESSION['_chosen_shipping_method'] = $this->posted['shipping_method'];
|
||||
$_SESSION['_chosen_payment_method'] = $this->posted['payment_method'];
|
||||
|
||||
// Update cart totals
|
||||
$woocommerce->cart->calculate_totals();
|
||||
|
||||
// Note if we skip shipping
|
||||
$skipped_shipping = false;
|
||||
|
||||
// Get posted checkout_fields and do validation
|
||||
foreach ($this->checkout_fields as $fieldset_key => $fieldset) :
|
||||
|
||||
// Skip shipping if its not needed
|
||||
if ($fieldset_key=='shipping' && (!$woocommerce->cart->needs_shipping() || $woocommerce->cart->ship_to_billing_address_only() || $this->posted['shiptobilling'])) :
|
||||
$skipped_shipping = true;
|
||||
continue;
|
||||
endif;
|
||||
|
||||
do_action('woocommerce_checkout_process');
|
||||
|
||||
// Checkout fields (not defined in checkout_fields)
|
||||
$this->posted['shiptobilling'] = isset($_POST['shiptobilling']) ? 1 : 0;
|
||||
$this->posted['terms'] = isset($_POST['terms']) ? 1 : 0;
|
||||
$this->posted['createaccount'] = isset($_POST['createaccount']) ? 1 : 0;
|
||||
$this->posted['payment_method'] = isset($_POST['payment_method']) ? woocommerce_clean($_POST['payment_method']) : '';
|
||||
$this->posted['shipping_method'] = isset($_POST['shipping_method']) ? woocommerce_clean($_POST['shipping_method']) : '';
|
||||
|
||||
// Ship to billing only option
|
||||
if ($woocommerce->cart->ship_to_billing_address_only()) $this->posted['shiptobilling'] = 1;
|
||||
|
||||
// Update customer shipping and payment method to posted method
|
||||
$_SESSION['_chosen_shipping_method'] = $this->posted['shipping_method'];
|
||||
$_SESSION['_chosen_payment_method'] = $this->posted['payment_method'];
|
||||
|
||||
// Update cart totals
|
||||
$woocommerce->cart->calculate_totals();
|
||||
|
||||
// Note if we skip shipping
|
||||
$skipped_shipping = false;
|
||||
|
||||
// Get posted checkout_fields and do validation
|
||||
foreach ($this->checkout_fields as $fieldset_key => $fieldset) :
|
||||
foreach ($fieldset as $key => $field) :
|
||||
|
||||
// Skip shipping if its not needed
|
||||
if ($fieldset_key=='shipping' && (!$woocommerce->cart->needs_shipping() || $woocommerce->cart->ship_to_billing_address_only() || $this->posted['shiptobilling'])) :
|
||||
$skipped_shipping = true;
|
||||
continue;
|
||||
endif;
|
||||
if (!isset($field['type'])) $field['type'] = 'text';
|
||||
|
||||
foreach ($fieldset as $key => $field) :
|
||||
|
||||
if (!isset($field['type'])) $field['type'] = 'text';
|
||||
|
||||
// Get Value
|
||||
switch ($field['type']) :
|
||||
case "checkbox" :
|
||||
$this->posted[$key] = isset($_POST[$key]) ? 1 : 0;
|
||||
// Get Value
|
||||
switch ($field['type']) :
|
||||
case "checkbox" :
|
||||
$this->posted[$key] = isset($_POST[$key]) ? 1 : 0;
|
||||
break;
|
||||
default :
|
||||
$this->posted[$key] = isset($_POST[$key]) ? woocommerce_clean($_POST[$key]) : '';
|
||||
break;
|
||||
endswitch;
|
||||
|
||||
// Hook to allow modification of value
|
||||
$this->posted[$key] = apply_filters('woocommerce_process_checkout_field_' . $key, $this->posted[$key]);
|
||||
|
||||
// Validation: Required fields
|
||||
if ( isset($field['required']) && $field['required'] && empty($this->posted[$key]) ) $woocommerce->add_error( $field['label'] . ' ' . __('is a required field.', 'woocommerce') );
|
||||
|
||||
if (!empty($this->posted[$key])) :
|
||||
// Special handling for validation and formatting
|
||||
switch ($key) :
|
||||
case "billing_postcode" :
|
||||
case "shipping_postcode" :
|
||||
$this->posted[$key] = strtolower(str_replace(' ', '', $this->posted[$key]));
|
||||
|
||||
if (!$woocommerce->validation->is_postcode( $this->posted[$key], $_POST['billing_country'] )) : $woocommerce->add_error( $field['label'] . __(' (billing) is not a valid postcode/ZIP.', 'woocommerce') );
|
||||
else :
|
||||
$this->posted[$key] = $woocommerce->validation->format_postcode( $this->posted[$key], $_POST['billing_country'] );
|
||||
endif;
|
||||
break;
|
||||
default :
|
||||
$this->posted[$key] = isset($_POST[$key]) ? woocommerce_clean($_POST[$key]) : '';
|
||||
case "billing_phone" :
|
||||
if (!$woocommerce->validation->is_phone( $this->posted[$key] )) : $woocommerce->add_error( $field['label'] . ' ' . __('is not a valid number.', 'woocommerce') ); endif;
|
||||
break;
|
||||
case "billing_email" :
|
||||
if (!$woocommerce->validation->is_email( $this->posted[$key] )) : $woocommerce->add_error( $field['label'] . ' ' . __('is not a valid email address.', 'woocommerce') ); endif;
|
||||
break;
|
||||
endswitch;
|
||||
|
||||
// Hook to allow modification of value
|
||||
$this->posted[$key] = apply_filters('woocommerce_process_checkout_field_' . $key, $this->posted[$key]);
|
||||
|
||||
// Validation: Required fields
|
||||
if ( isset($field['required']) && $field['required'] && empty($this->posted[$key]) ) $woocommerce->add_error( $field['label'] . ' ' . __('is a required field.', 'woocommerce') );
|
||||
|
||||
if (!empty($this->posted[$key])) :
|
||||
// Special handling for validation and formatting
|
||||
switch ($key) :
|
||||
case "billing_postcode" :
|
||||
case "shipping_postcode" :
|
||||
$this->posted[$key] = strtolower(str_replace(' ', '', $this->posted[$key]));
|
||||
|
||||
if (!$woocommerce->validation->is_postcode( $this->posted[$key], $_POST['billing_country'] )) : $woocommerce->add_error( $field['label'] . __(' (billing) is not a valid postcode/ZIP.', 'woocommerce') );
|
||||
else :
|
||||
$this->posted[$key] = $woocommerce->validation->format_postcode( $this->posted[$key], $_POST['billing_country'] );
|
||||
endif;
|
||||
break;
|
||||
case "billing_phone" :
|
||||
if (!$woocommerce->validation->is_phone( $this->posted[$key] )) : $woocommerce->add_error( $field['label'] . ' ' . __('is not a valid number.', 'woocommerce') ); endif;
|
||||
break;
|
||||
case "billing_email" :
|
||||
if (!$woocommerce->validation->is_email( $this->posted[$key] )) : $woocommerce->add_error( $field['label'] . ' ' . __('is not a valid email address.', 'woocommerce') ); endif;
|
||||
break;
|
||||
endswitch;
|
||||
endif;
|
||||
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
endforeach;
|
||||
|
||||
endforeach;
|
||||
|
||||
// Update customer location to posted location so we can correctly check available shipping methods
|
||||
$woocommerce->customer->set_country( $this->posted['billing_country'] );
|
||||
$woocommerce->customer->set_state( $this->posted['billing_state'] );
|
||||
$woocommerce->customer->set_postcode( $this->posted['billing_postcode'] );
|
||||
|
||||
// Shipping Information
|
||||
if (!$skipped_shipping) :
|
||||
|
||||
// Update customer location to posted location so we can correctly check available shipping methods
|
||||
$woocommerce->customer->set_country( $this->posted['billing_country'] );
|
||||
$woocommerce->customer->set_state( $this->posted['billing_state'] );
|
||||
$woocommerce->customer->set_postcode( $this->posted['billing_postcode'] );
|
||||
$woocommerce->customer->set_shipping_country( $this->posted['shipping_country'] );
|
||||
$woocommerce->customer->set_shipping_state( $this->posted['shipping_state'] );
|
||||
$woocommerce->customer->set_shipping_postcode( $this->posted['shipping_postcode'] );
|
||||
|
||||
// Shipping Information
|
||||
if (!$skipped_shipping) :
|
||||
|
||||
// Update customer location to posted location so we can correctly check available shipping methods
|
||||
$woocommerce->customer->set_shipping_country( $this->posted['shipping_country'] );
|
||||
$woocommerce->customer->set_shipping_state( $this->posted['shipping_state'] );
|
||||
$woocommerce->customer->set_shipping_postcode( $this->posted['shipping_postcode'] );
|
||||
|
||||
else :
|
||||
else :
|
||||
|
||||
// Update customer location to posted location so we can correctly check available shipping methods
|
||||
$woocommerce->customer->set_shipping_country( $this->posted['billing_country'] );
|
||||
$woocommerce->customer->set_shipping_state( $this->posted['billing_state'] );
|
||||
$woocommerce->customer->set_shipping_postcode( $this->posted['billing_postcode'] );
|
||||
|
||||
// Update customer location to posted location so we can correctly check available shipping methods
|
||||
$woocommerce->customer->set_shipping_country( $this->posted['billing_country'] );
|
||||
$woocommerce->customer->set_shipping_state( $this->posted['billing_state'] );
|
||||
$woocommerce->customer->set_shipping_postcode( $this->posted['billing_postcode'] );
|
||||
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if (is_user_logged_in()) :
|
||||
$this->creating_account = false;
|
||||
elseif (isset($this->posted['createaccount']) && $this->posted['createaccount']) :
|
||||
$this->creating_account = true;
|
||||
elseif ($this->must_create_account) :
|
||||
$this->creating_account = true;
|
||||
else :
|
||||
$this->creating_account = false;
|
||||
if (is_user_logged_in()) :
|
||||
$this->creating_account = false;
|
||||
elseif (isset($this->posted['createaccount']) && $this->posted['createaccount']) :
|
||||
$this->creating_account = true;
|
||||
elseif ($this->must_create_account) :
|
||||
$this->creating_account = true;
|
||||
else :
|
||||
$this->creating_account = false;
|
||||
endif;
|
||||
|
||||
if ($this->creating_account) :
|
||||
|
||||
if ( empty($this->posted['account_username']) ) $woocommerce->add_error( __('Please enter an account username.', 'woocommerce') );
|
||||
if ( empty($this->posted['account_password']) ) $woocommerce->add_error( __('Please enter an account password.', 'woocommerce') );
|
||||
if ( $this->posted['account_password-2'] !== $this->posted['account_password'] ) $woocommerce->add_error( __('Passwords do not match.', 'woocommerce') );
|
||||
|
||||
// Check the username
|
||||
if ( !validate_username( $this->posted['account_username'] ) ) :
|
||||
$woocommerce->add_error( __('Invalid email/username.', 'woocommerce') );
|
||||
elseif ( username_exists( $this->posted['account_username'] ) ) :
|
||||
$woocommerce->add_error( __('An account is already registered with that username. Please choose another.', 'woocommerce') );
|
||||
endif;
|
||||
|
||||
if ($this->creating_account) :
|
||||
|
||||
if ( empty($this->posted['account_username']) ) $woocommerce->add_error( __('Please enter an account username.', 'woocommerce') );
|
||||
if ( empty($this->posted['account_password']) ) $woocommerce->add_error( __('Please enter an account password.', 'woocommerce') );
|
||||
if ( $this->posted['account_password-2'] !== $this->posted['account_password'] ) $woocommerce->add_error( __('Passwords do not match.', 'woocommerce') );
|
||||
|
||||
// Check the username
|
||||
if ( !validate_username( $this->posted['account_username'] ) ) :
|
||||
$woocommerce->add_error( __('Invalid email/username.', 'woocommerce') );
|
||||
elseif ( username_exists( $this->posted['account_username'] ) ) :
|
||||
$woocommerce->add_error( __('An account is already registered with that username. Please choose another.', 'woocommerce') );
|
||||
endif;
|
||||
|
||||
// Check the e-mail address
|
||||
if ( email_exists( $this->posted['billing_email'] ) ) :
|
||||
$woocommerce->add_error( __('An account is already registered with your email address. Please login.', 'woocommerce') );
|
||||
endif;
|
||||
|
||||
// Check the e-mail address
|
||||
if ( email_exists( $this->posted['billing_email'] ) ) :
|
||||
$woocommerce->add_error( __('An account is already registered with your email address. Please login.', 'woocommerce') );
|
||||
endif;
|
||||
|
||||
// Terms
|
||||
if (!isset($_POST['update_totals']) && empty($this->posted['terms']) && woocommerce_get_page_id('terms')>0 ) $woocommerce->add_error( __('You must accept our Terms & Conditions.', 'woocommerce') );
|
||||
endif;
|
||||
|
||||
// Terms
|
||||
if (!isset($_POST['woocommerce_checkout_update_totals']) && empty($this->posted['terms']) && woocommerce_get_page_id('terms')>0 ) $woocommerce->add_error( __('You must accept our Terms & Conditions.', 'woocommerce') );
|
||||
|
||||
if ($woocommerce->cart->needs_shipping()) :
|
||||
|
||||
if ($woocommerce->cart->needs_shipping()) :
|
||||
|
||||
// Shipping Method
|
||||
$available_methods = $woocommerce->shipping->get_available_shipping_methods();
|
||||
|
||||
if (!isset($available_methods[$this->posted['shipping_method']])) :
|
||||
$woocommerce->add_error( __('Invalid shipping method.', 'woocommerce') );
|
||||
endif;
|
||||
// Shipping Method
|
||||
$available_methods = $woocommerce->shipping->get_available_shipping_methods();
|
||||
|
||||
if (!isset($available_methods[$this->posted['shipping_method']])) :
|
||||
$woocommerce->add_error( __('Invalid shipping method.', 'woocommerce') );
|
||||
endif;
|
||||
|
||||
if ($woocommerce->cart->needs_payment()) :
|
||||
// Payment Method
|
||||
$available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
|
||||
if (!isset($available_gateways[$this->posted['payment_method']])) :
|
||||
$woocommerce->add_error( __('Invalid payment method.', 'woocommerce') );
|
||||
else :
|
||||
// Payment Method Field Validation
|
||||
$available_gateways[$this->posted['payment_method']]->validate_fields();
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
||||
if ($woocommerce->cart->needs_payment()) :
|
||||
// Payment Method
|
||||
$available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
|
||||
if (!isset($available_gateways[$this->posted['payment_method']])) :
|
||||
$woocommerce->add_error( __('Invalid payment method.', 'woocommerce') );
|
||||
else :
|
||||
// Payment Method Field Validation
|
||||
$available_gateways[$this->posted['payment_method']]->validate_fields();
|
||||
endif;
|
||||
endif;
|
||||
|
||||
do_action( 'woocommerce_after_checkout_validation', $this->posted );
|
||||
|
||||
if (!isset($_POST['woocommerce_checkout_update_totals']) && $woocommerce->error_count()==0) :
|
||||
|
||||
do_action( 'woocommerce_after_checkout_validation', $this->posted );
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
while (1) :
|
||||
|
||||
// Create customer account and log them in
|
||||
if ($this->creating_account && !$user_id) :
|
||||
|
||||
$reg_errors = new WP_Error();
|
||||
|
||||
if (!isset($_POST['update_totals']) && $woocommerce->error_count()==0) :
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
while (1) :
|
||||
do_action('woocommerce_register_post', $this->posted['account_username'], $this->posted['billing_email'], $reg_errors);
|
||||
|
||||
// Create customer account and log them in
|
||||
if ($this->creating_account && !$user_id) :
|
||||
|
||||
$reg_errors = new WP_Error();
|
||||
|
||||
do_action('woocommerce_register_post', $this->posted['account_username'], $this->posted['billing_email'], $reg_errors);
|
||||
|
||||
$errors = apply_filters( 'woocommerce_registration_errors', $reg_errors, $this->posted['account_username'], $this->posted['billing_email'] );
|
||||
|
||||
// if there are no errors, let's create the user account
|
||||
if ( !$reg_errors->get_error_code() ) :
|
||||
|
||||
$user_pass = $this->posted['account_password'];
|
||||
$user_id = wp_create_user( $this->posted['account_username'], $user_pass, $this->posted['billing_email'] );
|
||||
|
||||
if ( !$user_id ) :
|
||||
$woocommerce->add_error( '<strong>' . __('ERROR', 'woocommerce') . '</strong>: ' . __('Couldn’t register you... please contact us if you continue to have problems.', 'woocommerce') );
|
||||
break;
|
||||
endif;
|
||||
|
||||
// Change role
|
||||
wp_update_user( array ('ID' => $user_id, 'role' => 'customer') ) ;
|
||||
|
||||
// send the user a confirmation and their login details
|
||||
$mailer = $woocommerce->mailer();
|
||||
$mailer->customer_new_account( $user_id, $password );
|
||||
|
||||
// set the WP login cookie
|
||||
$secure_cookie = is_ssl() ? true : false;
|
||||
wp_set_auth_cookie($user_id, true, $secure_cookie);
|
||||
|
||||
else :
|
||||
$woocommerce->add_error( $reg_errors->get_error_message() );
|
||||
break;
|
||||
endif;
|
||||
|
||||
$errors = apply_filters( 'woocommerce_registration_errors', $reg_errors, $this->posted['account_username'], $this->posted['billing_email'] );
|
||||
|
||||
// if there are no errors, let's create the user account
|
||||
if ( !$reg_errors->get_error_code() ) :
|
||||
|
||||
$user_pass = $this->posted['account_password'];
|
||||
$user_id = wp_create_user( $this->posted['account_username'], $user_pass, $this->posted['billing_email'] );
|
||||
|
||||
if ( !$user_id ) :
|
||||
$woocommerce->add_error( '<strong>' . __('ERROR', 'woocommerce') . '</strong>: ' . __('Couldn’t register you... please contact us if you continue to have problems.', 'woocommerce') );
|
||||
break;
|
||||
endif;
|
||||
|
||||
// Change role
|
||||
wp_update_user( array ('ID' => $user_id, 'role' => 'customer') ) ;
|
||||
|
||||
// send the user a confirmation and their login details
|
||||
$mailer = $woocommerce->mailer();
|
||||
$mailer->customer_new_account( $user_id, $password );
|
||||
|
||||
// set the WP login cookie
|
||||
$secure_cookie = is_ssl() ? true : false;
|
||||
wp_set_auth_cookie($user_id, true, $secure_cookie);
|
||||
|
||||
else :
|
||||
$woocommerce->add_error( $reg_errors->get_error_message() );
|
||||
break;
|
||||
endif;
|
||||
|
||||
// Create Order (send cart variable so we can record items and reduce inventory). Only create if this is a new order, not if the payment was rejected last time.
|
||||
$_tax = new woocommerce_tax();
|
||||
|
||||
$order_data = array(
|
||||
'post_type' => 'shop_order',
|
||||
'post_title' => 'Order – '.date('F j, Y @ h:i A'),
|
||||
'post_status' => 'publish',
|
||||
'post_excerpt' => $this->posted['order_comments'],
|
||||
'post_author' => 1
|
||||
);
|
||||
endif;
|
||||
|
||||
// Create Order (send cart variable so we can record items and reduce inventory). Only create if this is a new order, not if the payment was rejected last time.
|
||||
$_tax = new woocommerce_tax();
|
||||
|
||||
$order_data = array(
|
||||
'post_type' => 'shop_order',
|
||||
'post_title' => 'Order – '.date('F j, Y @ h:i A'),
|
||||
'post_status' => 'publish',
|
||||
'post_excerpt' => $this->posted['order_comments'],
|
||||
'post_author' => 1
|
||||
);
|
||||
|
||||
// Cart items
|
||||
$order_items = array();
|
||||
// Cart items
|
||||
$order_items = array();
|
||||
|
||||
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) :
|
||||
|
||||
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) :
|
||||
|
||||
$_product = $values['data'];
|
||||
$_product = $values['data'];
|
||||
|
||||
// Store any item meta data - item meta class lets plugins add item meta in a standardized way
|
||||
$item_meta = new order_item_meta();
|
||||
// Store any item meta data - item meta class lets plugins add item meta in a standardized way
|
||||
$item_meta = new order_item_meta();
|
||||
|
||||
$item_meta->new_order_item( $values );
|
||||
|
||||
// Store variation data in meta so admin can view it
|
||||
if ($values['variation'] && is_array($values['variation'])) :
|
||||
foreach ($values['variation'] as $key => $value) :
|
||||
$item_meta->add( esc_attr(str_replace('attribute_', '', $key)), $value );
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
$order_items[] = apply_filters('new_order_item', array(
|
||||
'id' => $values['product_id'],
|
||||
'variation_id' => $values['variation_id'],
|
||||
'name' => $_product->get_title(),
|
||||
'qty' => (int) $values['quantity'],
|
||||
'item_meta' => $item_meta->meta,
|
||||
'base_tax' => number_format($values['base_tax'], 2, '.', ''), // Base tax (unit, before discounts)
|
||||
'base_cost' => number_format($values['base_cost'], 2, '.', ''), // Base price (unit, before discounts)
|
||||
'line_cost' => number_format($values['line_cost'], 2, '.', ''), // Discounted line cost
|
||||
'line_tax' => number_format($values['line_tax'], 2, '.', ''), // Tax for the line (total)
|
||||
'tax_status' => $_product->get_tax_status(), // Taxble, shipping, none
|
||||
'tax_class' => $_product->get_tax_class() // Tax class (adjusted by filters)
|
||||
), $values);
|
||||
|
||||
endforeach;
|
||||
|
||||
// Check order items for errors
|
||||
do_action('woocommerce_check_new_order_items', $order_items);
|
||||
|
||||
if ($woocommerce->error_count()>0) break;
|
||||
|
||||
// Insert or update the post data
|
||||
$create_new_order = true;
|
||||
|
||||
if (isset($_SESSION['order_awaiting_payment']) && $_SESSION['order_awaiting_payment'] > 0) :
|
||||
|
||||
$order_id = (int) $_SESSION['order_awaiting_payment'];
|
||||
|
||||
/* Check order is unpaid */
|
||||
$order = new woocommerce_order( $order_id );
|
||||
|
||||
if ( $order->status == 'pending' ) :
|
||||
|
||||
$item_meta->new_order_item( $values );
|
||||
// Resume the unpaid order
|
||||
$order_data['ID'] = $order_id;
|
||||
wp_update_post( $order_data );
|
||||
do_action('woocommerce_resume_order', $order_id);
|
||||
|
||||
// Store variation data in meta so admin can view it
|
||||
if ($values['variation'] && is_array($values['variation'])) :
|
||||
foreach ($values['variation'] as $key => $value) :
|
||||
$item_meta->add( esc_attr(str_replace('attribute_', '', $key)), $value );
|
||||
endforeach;
|
||||
$create_new_order = false;
|
||||
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
||||
if ($create_new_order) :
|
||||
$order_id = wp_insert_post( $order_data );
|
||||
|
||||
if (is_wp_error($order_id)) :
|
||||
$woocommerce->add_error( 'Error: Unable to create order. Please try again.' );
|
||||
break;
|
||||
else :
|
||||
// Inserted successfully
|
||||
do_action('woocommerce_new_order', $order_id);
|
||||
endif;
|
||||
endif;
|
||||
|
||||
// Get better formatted billing method (title)
|
||||
$shipping_method = $this->posted['shipping_method'];
|
||||
if (isset($available_methods) && isset($available_methods[$this->posted['shipping_method']])) :
|
||||
$shipping_method = $available_methods[$this->posted['shipping_method']]->label;
|
||||
endif;
|
||||
|
||||
// Get better formatted shipping method (title/label)
|
||||
$payment_method = $this->posted['payment_method'];
|
||||
if (isset($available_gateways) && isset($available_gateways[$this->posted['payment_method']])) :
|
||||
$payment_method = $available_gateways[$this->posted['payment_method']]->title;
|
||||
endif;
|
||||
|
||||
// UPDATE ORDER META
|
||||
|
||||
// Save billing and shipping first, also save to user meta if logged in
|
||||
if ($this->checkout_fields['billing']) :
|
||||
foreach ($this->checkout_fields['billing'] as $key => $field) :
|
||||
|
||||
// Post
|
||||
update_post_meta( $order_id, '_' . $key, $this->posted[$key] );
|
||||
|
||||
// User
|
||||
if ($user_id>0) :
|
||||
update_user_meta( $user_id, $key, $this->posted[$key] );
|
||||
endif;
|
||||
|
||||
$order_items[] = apply_filters('new_order_item', array(
|
||||
'id' => $values['product_id'],
|
||||
'variation_id' => $values['variation_id'],
|
||||
'name' => $_product->get_title(),
|
||||
'qty' => (int) $values['quantity'],
|
||||
'item_meta' => $item_meta->meta,
|
||||
'base_tax' => number_format($values['base_tax'], 2, '.', ''), // Base tax (unit, before discounts)
|
||||
'base_cost' => number_format($values['base_cost'], 2, '.', ''), // Base price (unit, before discounts)
|
||||
'line_cost' => number_format($values['line_cost'], 2, '.', ''), // Discounted line cost
|
||||
'line_tax' => number_format($values['line_tax'], 2, '.', ''), // Tax for the line (total)
|
||||
'tax_status' => $_product->get_tax_status(), // Taxble, shipping, none
|
||||
'tax_class' => $_product->get_tax_class() // Tax class (adjusted by filters)
|
||||
), $values);
|
||||
|
||||
// Check cart items for errors
|
||||
do_action('woocommerce_check_cart_items', $order_items);
|
||||
|
||||
endforeach;
|
||||
|
||||
if ($woocommerce->error_count()>0) break;
|
||||
|
||||
// Insert or update the post data
|
||||
$create_new_order = true;
|
||||
|
||||
if (isset($_SESSION['order_awaiting_payment']) && $_SESSION['order_awaiting_payment'] > 0) :
|
||||
endif;
|
||||
if ($this->checkout_fields['shipping'] && $woocommerce->cart->needs_shipping()) :
|
||||
foreach ($this->checkout_fields['shipping'] as $key => $field) :
|
||||
|
||||
$order_id = (int) $_SESSION['order_awaiting_payment'];
|
||||
|
||||
/* Check order is unpaid */
|
||||
$order = new woocommerce_order( $order_id );
|
||||
|
||||
if ( $order->status == 'pending' ) :
|
||||
if ($this->posted['shiptobilling']) :
|
||||
|
||||
// Resume the unpaid order
|
||||
$order_data['ID'] = $order_id;
|
||||
wp_update_post( $order_data );
|
||||
do_action('woocommerce_resume_order', $order_id);
|
||||
$field_key = str_replace('shipping_', 'billing_', $key);
|
||||
|
||||
$create_new_order = false;
|
||||
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
||||
if ($create_new_order) :
|
||||
$order_id = wp_insert_post( $order_data );
|
||||
|
||||
if (is_wp_error($order_id)) :
|
||||
$woocommerce->add_error( 'Error: Unable to create order. Please try again.' );
|
||||
break;
|
||||
// Post
|
||||
update_post_meta( $order_id, '_' . $key, $this->posted[$field_key] );
|
||||
|
||||
// User
|
||||
if ($user_id>0) :
|
||||
update_user_meta( $user_id, $key, $this->posted[$field_key] );
|
||||
endif;
|
||||
else :
|
||||
// Inserted successfully
|
||||
do_action('woocommerce_new_order', $order_id);
|
||||
endif;
|
||||
endif;
|
||||
|
||||
// Get better formatted billing method (title)
|
||||
$shipping_method = $this->posted['shipping_method'];
|
||||
if (isset($available_methods) && isset($available_methods[$this->posted['shipping_method']])) :
|
||||
$shipping_method = $available_methods[$this->posted['shipping_method']]->label;
|
||||
endif;
|
||||
|
||||
// Get better formatted shipping method (title/label)
|
||||
$payment_method = $this->posted['payment_method'];
|
||||
if (isset($available_gateways) && isset($available_gateways[$this->posted['payment_method']])) :
|
||||
$payment_method = $available_gateways[$this->posted['payment_method']]->title;
|
||||
endif;
|
||||
|
||||
// UPDATE ORDER META
|
||||
|
||||
// Save billing and shipping first, also save to user meta if logged in
|
||||
if ($this->checkout_fields['billing']) :
|
||||
foreach ($this->checkout_fields['billing'] as $key => $field) :
|
||||
|
||||
// Post
|
||||
update_post_meta( $order_id, '_' . $key, $this->posted[$key] );
|
||||
|
||||
|
@ -480,141 +503,109 @@ class woocommerce_checkout {
|
|||
if ($user_id>0) :
|
||||
update_user_meta( $user_id, $key, $this->posted[$key] );
|
||||
endif;
|
||||
|
||||
endforeach;
|
||||
endif;
|
||||
if ($this->checkout_fields['shipping'] && $woocommerce->cart->needs_shipping()) :
|
||||
foreach ($this->checkout_fields['shipping'] as $key => $field) :
|
||||
|
||||
if ($this->posted['shiptobilling']) :
|
||||
|
||||
$field_key = str_replace('shipping_', 'billing_', $key);
|
||||
|
||||
// Post
|
||||
update_post_meta( $order_id, '_' . $key, $this->posted[$field_key] );
|
||||
|
||||
// User
|
||||
if ($user_id>0) :
|
||||
update_user_meta( $user_id, $key, $this->posted[$field_key] );
|
||||
endif;
|
||||
else :
|
||||
// Post
|
||||
update_post_meta( $order_id, '_' . $key, $this->posted[$key] );
|
||||
|
||||
// User
|
||||
if ($user_id>0) :
|
||||
update_user_meta( $user_id, $key, $this->posted[$key] );
|
||||
endif;
|
||||
endif;
|
||||
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
// Put order taxes into an array to store
|
||||
$order_taxes = array();
|
||||
|
||||
if (is_array($woocommerce->cart->taxes) && sizeof($woocommerce->cart->taxes)>0) foreach ( $woocommerce->cart->taxes as $key => $tax ) :
|
||||
|
||||
$is_compound = ($woocommerce->cart->tax->is_compound( $key )) ? 1 : 0;
|
||||
|
||||
$order_taxes[] = array(
|
||||
'label' => $woocommerce->cart->tax->get_rate_label( $key ),
|
||||
'compound' => $is_compound,
|
||||
'total' => number_format($tax, 2, '.', '')
|
||||
);
|
||||
endif;
|
||||
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
// Put order taxes into an array to store
|
||||
$order_taxes = array();
|
||||
|
||||
if (is_array($woocommerce->cart->taxes) && sizeof($woocommerce->cart->taxes)>0) foreach ( $woocommerce->cart->taxes as $key => $tax ) :
|
||||
|
||||
// Save other order meta fields
|
||||
update_post_meta( $order_id, '_shipping_method', $this->posted['shipping_method']);
|
||||
update_post_meta( $order_id, '_payment_method', $this->posted['payment_method']);
|
||||
update_post_meta( $order_id, '_shipping_method_title', $shipping_method);
|
||||
update_post_meta( $order_id, '_payment_method_title', $payment_method);
|
||||
update_post_meta( $order_id, '_order_shipping', number_format($woocommerce->cart->shipping_total, 2, '.', ''));
|
||||
update_post_meta( $order_id, '_order_discount', number_format($woocommerce->cart->get_order_discount_total(), 2, '.', ''));
|
||||
update_post_meta( $order_id, '_cart_discount', number_format($woocommerce->cart->get_cart_discount_total(), 2, '.', ''));
|
||||
update_post_meta( $order_id, '_order_tax', number_format($woocommerce->cart->tax_total, 2, '.', ''));
|
||||
update_post_meta( $order_id, '_order_shipping_tax', number_format($woocommerce->cart->shipping_tax_total, 2, '.', ''));
|
||||
update_post_meta( $order_id, '_order_total', number_format($woocommerce->cart->total, 2, '.', ''));
|
||||
update_post_meta( $order_id, '_order_key', apply_filters('woocommerce_generate_order_key', uniqid('order_') ));
|
||||
update_post_meta( $order_id, '_customer_user', (int) $user_id );
|
||||
update_post_meta( $order_id, '_order_items', $order_items );
|
||||
update_post_meta( $order_id, '_order_taxes', $order_taxes );
|
||||
$is_compound = ($woocommerce->cart->tax->is_compound( $key )) ? 1 : 0;
|
||||
|
||||
do_action('woocommerce_checkout_update_order_meta', $order_id, $this->posted);
|
||||
$order_taxes[] = array(
|
||||
'label' => $woocommerce->cart->tax->get_rate_label( $key ),
|
||||
'compound' => $is_compound,
|
||||
'total' => number_format($tax, 2, '.', '')
|
||||
);
|
||||
|
||||
// Order status
|
||||
wp_set_object_terms( $order_id, 'pending', 'shop_order_status' );
|
||||
|
||||
// Discount code meta
|
||||
if ($applied_coupons = $woocommerce->cart->get_applied_coupons()) update_post_meta($order_id, 'coupons', implode(', ', $applied_coupons));
|
||||
endforeach;
|
||||
|
||||
// Save other order meta fields
|
||||
update_post_meta( $order_id, '_shipping_method', $this->posted['shipping_method']);
|
||||
update_post_meta( $order_id, '_payment_method', $this->posted['payment_method']);
|
||||
update_post_meta( $order_id, '_shipping_method_title', $shipping_method);
|
||||
update_post_meta( $order_id, '_payment_method_title', $payment_method);
|
||||
update_post_meta( $order_id, '_order_shipping', number_format($woocommerce->cart->shipping_total, 2, '.', ''));
|
||||
update_post_meta( $order_id, '_order_discount', number_format($woocommerce->cart->get_order_discount_total(), 2, '.', ''));
|
||||
update_post_meta( $order_id, '_cart_discount', number_format($woocommerce->cart->get_cart_discount_total(), 2, '.', ''));
|
||||
update_post_meta( $order_id, '_order_tax', number_format($woocommerce->cart->tax_total, 2, '.', ''));
|
||||
update_post_meta( $order_id, '_order_shipping_tax', number_format($woocommerce->cart->shipping_tax_total, 2, '.', ''));
|
||||
update_post_meta( $order_id, '_order_total', number_format($woocommerce->cart->total, 2, '.', ''));
|
||||
update_post_meta( $order_id, '_order_key', apply_filters('woocommerce_generate_order_key', uniqid('order_') ));
|
||||
update_post_meta( $order_id, '_customer_user', (int) $user_id );
|
||||
update_post_meta( $order_id, '_order_items', $order_items );
|
||||
update_post_meta( $order_id, '_order_taxes', $order_taxes );
|
||||
|
||||
do_action('woocommerce_checkout_update_order_meta', $order_id, $this->posted);
|
||||
|
||||
// Order status
|
||||
wp_set_object_terms( $order_id, 'pending', 'shop_order_status' );
|
||||
|
||||
// Order is saved
|
||||
do_action('woocommerce_checkout_order_processed', $order_id, $this->posted);
|
||||
// Discount code meta
|
||||
if ($applied_coupons = $woocommerce->cart->get_applied_coupons()) update_post_meta($order_id, 'coupons', implode(', ', $applied_coupons));
|
||||
|
||||
// Order is saved
|
||||
do_action('woocommerce_checkout_order_processed', $order_id, $this->posted);
|
||||
|
||||
// Process payment
|
||||
if ($woocommerce->cart->needs_payment()) :
|
||||
|
||||
// Process payment
|
||||
if ($woocommerce->cart->needs_payment()) :
|
||||
|
||||
// Store Order ID in session so it can be re-used after payment failure
|
||||
$_SESSION['order_awaiting_payment'] = $order_id;
|
||||
// Store Order ID in session so it can be re-used after payment failure
|
||||
$_SESSION['order_awaiting_payment'] = $order_id;
|
||||
|
||||
// Process Payment
|
||||
$result = $available_gateways[$this->posted['payment_method']]->process_payment( $order_id );
|
||||
|
||||
// Redirect to success/confirmation/payment page
|
||||
if ($result['result']=='success') :
|
||||
|
||||
$result = apply_filters('woocommerce_payment_successful_result', $result );
|
||||
|
||||
if (is_ajax()) :
|
||||
ob_clean();
|
||||
echo json_encode( $result );
|
||||
exit;
|
||||
else :
|
||||
wp_safe_redirect( $result['redirect'] );
|
||||
exit;
|
||||
endif;
|
||||
|
||||
endif;
|
||||
// Process Payment
|
||||
$result = $available_gateways[$this->posted['payment_method']]->process_payment( $order_id );
|
||||
|
||||
else :
|
||||
// Redirect to success/confirmation/payment page
|
||||
if ($result['result']=='success') :
|
||||
|
||||
$order = new woocommerce_order($order_id);
|
||||
$result = apply_filters('woocommerce_payment_successful_result', $result );
|
||||
|
||||
// No payment was required for order
|
||||
$order->payment_complete();
|
||||
|
||||
// Empty the Cart
|
||||
$woocommerce->cart->empty_cart();
|
||||
|
||||
// Redirect to success/confirmation/payment page
|
||||
if (is_ajax()) :
|
||||
ob_clean();
|
||||
echo json_encode( array('redirect' => apply_filters( 'woocommerce_checkout_no_payment_needed_redirect', get_permalink(woocommerce_get_page_id('thanks')))) );
|
||||
echo json_encode( $result );
|
||||
exit;
|
||||
else :
|
||||
wp_safe_redirect( apply_filters( 'woocommerce_checkout_no_payment_needed_redirect', get_permalink(woocommerce_get_page_id('thanks'))) );
|
||||
wp_safe_redirect( $result['redirect'] );
|
||||
exit;
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
||||
// Break out of loop
|
||||
break;
|
||||
|
||||
endwhile;
|
||||
|
||||
endif;
|
||||
else :
|
||||
|
||||
$order = new woocommerce_order($order_id);
|
||||
|
||||
// No payment was required for order
|
||||
$order->payment_complete();
|
||||
|
||||
// Empty the Cart
|
||||
$woocommerce->cart->empty_cart();
|
||||
|
||||
// Redirect to success/confirmation/payment page
|
||||
if (is_ajax()) :
|
||||
echo json_encode( array('redirect' => apply_filters( 'woocommerce_checkout_no_payment_needed_redirect', get_permalink(woocommerce_get_page_id('thanks')))) );
|
||||
exit;
|
||||
else :
|
||||
wp_safe_redirect( apply_filters( 'woocommerce_checkout_no_payment_needed_redirect', get_permalink(woocommerce_get_page_id('thanks'))) );
|
||||
exit;
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
||||
// Break out of loop
|
||||
break;
|
||||
|
||||
// If we reached this point then there were errors
|
||||
if (is_ajax()) :
|
||||
ob_clean();
|
||||
$woocommerce->show_messages();
|
||||
exit;
|
||||
else :
|
||||
$woocommerce->show_messages();
|
||||
endif;
|
||||
endwhile;
|
||||
|
||||
endif;
|
||||
|
||||
// If we reached this point then there were errors
|
||||
if (is_ajax()) :
|
||||
$woocommerce->show_messages();
|
||||
exit;
|
||||
endif;
|
||||
}
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ class woocommerce_bacs extends woocommerce_payment_gateway {
|
|||
// Return thankyou redirect
|
||||
return array(
|
||||
'result' => 'success',
|
||||
'redirect' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(woocommerce_get_page_id('thanks'))))
|
||||
'redirect' => add_query_arg('key', $order->order_key, add_query_arg('order', $order->id, get_permalink(woocommerce_get_page_id('thanks'))))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,143 +1,143 @@
|
|||
<?php
|
||||
/**
|
||||
* Cheque Payment Gateway
|
||||
*
|
||||
* Provides a Cheque Payment Gateway, mainly for testing purposes.
|
||||
*
|
||||
* @class woocommerce_cheque
|
||||
* @package WooCommerce
|
||||
* @category Payment Gateways
|
||||
* @author WooThemes
|
||||
*/
|
||||
class woocommerce_cheque extends woocommerce_payment_gateway {
|
||||
|
||||
public function __construct() {
|
||||
$this->id = 'cheque';
|
||||
$this->icon = apply_filters('woocommerce_cheque_icon', '');
|
||||
$this->has_fields = false;
|
||||
|
||||
// Load the form fields.
|
||||
$this->init_form_fields();
|
||||
|
||||
// Load the settings.
|
||||
$this->init_settings();
|
||||
|
||||
// Define user set variables
|
||||
$this->title = $this->settings['title'];
|
||||
$this->description = $this->settings['description'];
|
||||
|
||||
// Actions
|
||||
add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
|
||||
add_action('woocommerce_thankyou_cheque', array(&$this, 'thankyou_page'));
|
||||
|
||||
// Customer Emails
|
||||
add_action('woocommerce_email_before_order_table', array(&$this, 'email_instructions'), 10, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise Gateway Settings Form Fields
|
||||
*/
|
||||
function init_form_fields() {
|
||||
|
||||
$this->form_fields = array(
|
||||
'enabled' => array(
|
||||
'title' => __( 'Enable/Disable', 'woocommerce' ),
|
||||
'type' => 'checkbox',
|
||||
'label' => __( 'Enable Cheque Payment', 'woocommerce' ),
|
||||
'default' => 'yes'
|
||||
),
|
||||
'title' => array(
|
||||
'title' => __( 'Title', 'woocommerce' ),
|
||||
'type' => 'text',
|
||||
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
|
||||
'default' => __( 'Cheque Payment', 'woocommerce' )
|
||||
),
|
||||
'description' => array(
|
||||
'title' => __( 'Customer Message', 'woocommerce' ),
|
||||
'type' => 'textarea',
|
||||
'description' => __( 'Let the customer know the payee and where they should be sending the cheque to and that their order won\'t be shipping until you receive it.', 'woocommerce' ),
|
||||
'default' => 'Please send your cheque to Store Name, Store Street, Store Town, Store State / County, Store Postcode.'
|
||||
)
|
||||
);
|
||||
|
||||
} // End init_form_fields()
|
||||
|
||||
/**
|
||||
* Admin Panel Options
|
||||
* - Options for bits like 'title' and availability on a country-by-country basis
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function admin_options() {
|
||||
|
||||
?>
|
||||
<h3><?php _e('Cheque Payment', 'woocommerce'); ?></h3>
|
||||
<p><?php _e('Allows cheque payments. Why would you take cheques in this day and age? Well you probably wouldn\'t but it does allow you to make test purchases for testing order emails and the \'success\' pages etc.', 'woocommerce'); ?></p>
|
||||
<table class="form-table">
|
||||
<?php
|
||||
// Generate the HTML For the settings form.
|
||||
$this->generate_settings_html();
|
||||
?>
|
||||
</table><!--/.form-table-->
|
||||
<?php
|
||||
} // End admin_options()
|
||||
|
||||
/**
|
||||
* There are no payment fields for cheques, but we want to show the description if set.
|
||||
**/
|
||||
function payment_fields() {
|
||||
if ($this->description) echo wpautop(wptexturize($this->description));
|
||||
}
|
||||
|
||||
function thankyou_page() {
|
||||
if ($this->description) echo wpautop(wptexturize($this->description));
|
||||
}
|
||||
|
||||
function email_instructions( $order, $sent_to_admin ) {
|
||||
if ( $sent_to_admin ) return;
|
||||
|
||||
if ( $order->status !== 'on-hold') return;
|
||||
|
||||
if ( $order->payment_method !== 'cheque') return;
|
||||
|
||||
if ($this->description) echo wpautop(wptexturize($this->description));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the payment and return the result
|
||||
**/
|
||||
function process_payment( $order_id ) {
|
||||
<?php
|
||||
/**
|
||||
* Cheque Payment Gateway
|
||||
*
|
||||
* Provides a Cheque Payment Gateway, mainly for testing purposes.
|
||||
*
|
||||
* @class woocommerce_cheque
|
||||
* @package WooCommerce
|
||||
* @category Payment Gateways
|
||||
* @author WooThemes
|
||||
*/
|
||||
class woocommerce_cheque extends woocommerce_payment_gateway {
|
||||
|
||||
public function __construct() {
|
||||
$this->id = 'cheque';
|
||||
$this->icon = apply_filters('woocommerce_cheque_icon', '');
|
||||
$this->has_fields = false;
|
||||
|
||||
// Load the form fields.
|
||||
$this->init_form_fields();
|
||||
|
||||
// Load the settings.
|
||||
$this->init_settings();
|
||||
|
||||
// Define user set variables
|
||||
$this->title = $this->settings['title'];
|
||||
$this->description = $this->settings['description'];
|
||||
|
||||
// Actions
|
||||
add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
|
||||
add_action('woocommerce_thankyou_cheque', array(&$this, 'thankyou_page'));
|
||||
|
||||
// Customer Emails
|
||||
add_action('woocommerce_email_before_order_table', array(&$this, 'email_instructions'), 10, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise Gateway Settings Form Fields
|
||||
*/
|
||||
function init_form_fields() {
|
||||
|
||||
$this->form_fields = array(
|
||||
'enabled' => array(
|
||||
'title' => __( 'Enable/Disable', 'woocommerce' ),
|
||||
'type' => 'checkbox',
|
||||
'label' => __( 'Enable Cheque Payment', 'woocommerce' ),
|
||||
'default' => 'yes'
|
||||
),
|
||||
'title' => array(
|
||||
'title' => __( 'Title', 'woocommerce' ),
|
||||
'type' => 'text',
|
||||
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
|
||||
'default' => __( 'Cheque Payment', 'woocommerce' )
|
||||
),
|
||||
'description' => array(
|
||||
'title' => __( 'Customer Message', 'woocommerce' ),
|
||||
'type' => 'textarea',
|
||||
'description' => __( 'Let the customer know the payee and where they should be sending the cheque to and that their order won\'t be shipping until you receive it.', 'woocommerce' ),
|
||||
'default' => 'Please send your cheque to Store Name, Store Street, Store Town, Store State / County, Store Postcode.'
|
||||
)
|
||||
);
|
||||
|
||||
} // End init_form_fields()
|
||||
|
||||
/**
|
||||
* Admin Panel Options
|
||||
* - Options for bits like 'title' and availability on a country-by-country basis
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function admin_options() {
|
||||
|
||||
?>
|
||||
<h3><?php _e('Cheque Payment', 'woocommerce'); ?></h3>
|
||||
<p><?php _e('Allows cheque payments. Why would you take cheques in this day and age? Well you probably wouldn\'t but it does allow you to make test purchases for testing order emails and the \'success\' pages etc.', 'woocommerce'); ?></p>
|
||||
<table class="form-table">
|
||||
<?php
|
||||
// Generate the HTML For the settings form.
|
||||
$this->generate_settings_html();
|
||||
?>
|
||||
</table><!--/.form-table-->
|
||||
<?php
|
||||
} // End admin_options()
|
||||
|
||||
/**
|
||||
* There are no payment fields for cheques, but we want to show the description if set.
|
||||
**/
|
||||
function payment_fields() {
|
||||
if ($this->description) echo wpautop(wptexturize($this->description));
|
||||
}
|
||||
|
||||
function thankyou_page() {
|
||||
if ($this->description) echo wpautop(wptexturize($this->description));
|
||||
}
|
||||
|
||||
function email_instructions( $order, $sent_to_admin ) {
|
||||
if ( $sent_to_admin ) return;
|
||||
|
||||
if ( $order->status !== 'on-hold') return;
|
||||
|
||||
if ( $order->payment_method !== 'cheque') return;
|
||||
|
||||
if ($this->description) echo wpautop(wptexturize($this->description));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the payment and return the result
|
||||
**/
|
||||
function process_payment( $order_id ) {
|
||||
global $woocommerce;
|
||||
|
||||
$order = new woocommerce_order( $order_id );
|
||||
|
||||
// Mark as on-hold (we're awaiting the cheque)
|
||||
$order->update_status('on-hold', __('Awaiting cheque payment', 'woocommerce'));
|
||||
|
||||
// Reduce stock levels
|
||||
$order->reduce_order_stock();
|
||||
|
||||
// Remove cart
|
||||
$woocommerce->cart->empty_cart();
|
||||
|
||||
// Empty awaiting payment session
|
||||
unset($_SESSION['order_awaiting_payment']);
|
||||
|
||||
// Return thankyou redirect
|
||||
return array(
|
||||
'result' => 'success',
|
||||
'redirect' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(woocommerce_get_page_id('thanks'))))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the gateway to WooCommerce
|
||||
**/
|
||||
function add_cheque_gateway( $methods ) {
|
||||
$methods[] = 'woocommerce_cheque'; return $methods;
|
||||
}
|
||||
|
||||
add_filter('woocommerce_payment_gateways', 'add_cheque_gateway' );
|
||||
|
||||
$order = new woocommerce_order( $order_id );
|
||||
|
||||
// Mark as on-hold (we're awaiting the cheque)
|
||||
$order->update_status('on-hold', __('Awaiting cheque payment', 'woocommerce'));
|
||||
|
||||
// Reduce stock levels
|
||||
$order->reduce_order_stock();
|
||||
|
||||
// Remove cart
|
||||
$woocommerce->cart->empty_cart();
|
||||
|
||||
// Empty awaiting payment session
|
||||
unset($_SESSION['order_awaiting_payment']);
|
||||
|
||||
// Return thankyou redirect
|
||||
return array(
|
||||
'result' => 'success',
|
||||
'redirect' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(woocommerce_get_page_id('thanks'))))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the gateway to WooCommerce
|
||||
**/
|
||||
function add_cheque_gateway( $methods ) {
|
||||
$methods[] = 'woocommerce_cheque'; return $methods;
|
||||
}
|
||||
|
||||
add_filter('woocommerce_payment_gateways', 'add_cheque_gateway' );
|
||||
|
|
|
@ -22,7 +22,7 @@ class woocommerce_order {
|
|||
}
|
||||
|
||||
/** Get the order if ID is passed, otherwise the order is new and empty */
|
||||
function woocommerce_order( $id='' ) {
|
||||
function __construct ( $id='' ) {
|
||||
$this->calc_taxes = (get_option('woocommerce_calc_taxes')=='yes') ? true : false;
|
||||
$this->prices_include_tax = (get_option('woocommerce_prices_include_tax')=='yes') ? true : false;
|
||||
$this->display_totals_ex_tax = (get_option('woocommerce_display_totals_excluding_tax')=='yes') ? true : false;
|
||||
|
@ -682,7 +682,7 @@ class woocommerce_order {
|
|||
$this->add_order_note( sprintf( __('Item #%s stock reduced from %s to %s.', 'woocommerce'), $item['id'], $old_stock, $new_quantity) );
|
||||
|
||||
if ($new_quantity<0) :
|
||||
do_action('woocommerce_product_on_backorder', array( 'product' => $item['id'], 'order_id' => $this->id, 'quantity' => $item['quantity']));
|
||||
do_action('woocommerce_product_on_backorder', array( 'product' => $item['id'], 'order_id' => $this->id, 'quantity' => $item['qty']));
|
||||
endif;
|
||||
|
||||
// stock status notifications
|
||||
|
|
|
@ -440,7 +440,7 @@ class woocommerce_product {
|
|||
}
|
||||
|
||||
/** Returns whether or not the product is visible */
|
||||
function is_visible( $single = false ) {
|
||||
function is_visible() {
|
||||
|
||||
$visible = true;
|
||||
|
||||
|
@ -450,7 +450,6 @@ class woocommerce_product {
|
|||
// visibility setting
|
||||
elseif ($this->visibility=='hidden') $visible = false;
|
||||
elseif ($this->visibility=='visible') $visible = true;
|
||||
elseif ($single) $visible = true;
|
||||
|
||||
// Visibility in loop
|
||||
elseif ($this->visibility=='search' && is_search()) $visible = true;
|
||||
|
|
|
@ -91,9 +91,8 @@ class woocommerce_email {
|
|||
return $message;
|
||||
}
|
||||
|
||||
function send( $to, $subject, $message, $headers = '', $attachments = "" ) {
|
||||
if (!$headers) $headers = "Content-Type: text/html\r\n";
|
||||
|
||||
function send( $to, $subject, $message, $headers = "", $attachments = "" ) {
|
||||
|
||||
add_filter( 'wp_mail_from', array(&$this, 'get_from_address') );
|
||||
add_filter( 'wp_mail_from_name', array(&$this, 'get_from_name') );
|
||||
add_filter( 'wp_mail_content_type', array(&$this, 'get_content_type') );
|
||||
|
|
|
@ -120,8 +120,10 @@ Yes you can! Join in on our GitHub repository :) https://github.com/woothemes/wo
|
|||
* Change textdomain from woothemes to woocommerce
|
||||
* Free shipping coupons ignore min-amount
|
||||
* Delete all variations option
|
||||
* Removed the need of ob_start on most frontend pages to improve page loading speed
|
||||
* Product category widget option to show current children only
|
||||
* Updated default styles
|
||||
* Tweaked visibility settings and made them more clear
|
||||
|
||||
= 1.3.2.1 - 15/12/2011 =
|
||||
* Category/Ordering fix
|
||||
|
|
|
@ -15,25 +15,15 @@ function get_woocommerce_checkout( $atts ) {
|
|||
}
|
||||
|
||||
function woocommerce_checkout( $atts ) {
|
||||
global $woocommerce, $woocommerce_checkout;
|
||||
global $woocommerce;
|
||||
|
||||
if (!defined('WOOCOMMERCE_CHECKOUT')) define('WOOCOMMERCE_CHECKOUT', true);
|
||||
if (sizeof($woocommerce->cart->get_cart())==0) return;
|
||||
|
||||
if (sizeof($woocommerce->cart->get_cart())==0) :
|
||||
wp_redirect(get_permalink(woocommerce_get_page_id('cart')));
|
||||
exit;
|
||||
endif;
|
||||
|
||||
$non_js_checkout = (isset($_POST['update_totals']) && $_POST['update_totals']) ? true : false;
|
||||
|
||||
$woocommerce_checkout = $woocommerce->checkout();
|
||||
|
||||
$woocommerce_checkout->process_checkout();
|
||||
$non_js_checkout = (isset($_POST['woocommerce_checkout_update_totals']) && $_POST['woocommerce_checkout_update_totals']) ? true : false;
|
||||
|
||||
do_action('woocommerce_check_cart_items');
|
||||
|
||||
if ( $woocommerce->error_count()==0 && $non_js_checkout) $woocommerce->add_message( __('The order totals have been updated. Please confirm your order by pressing the Place Order button at the bottom of the page.', 'woocommerce') );
|
||||
|
||||
woocommerce_get_template('checkout/form.php', false);
|
||||
|
||||
}
|
|
@ -72,10 +72,7 @@ function woocommerce_my_account( $atts ) {
|
|||
function woocommerce_edit_address() {
|
||||
global $woocommerce, $load_address, $address;
|
||||
|
||||
if ( ! is_user_logged_in() ) :
|
||||
wp_safe_redirect( get_permalink( woocommerce_get_page_id('myaccount') ) );
|
||||
exit;
|
||||
endif;
|
||||
if ( ! is_user_logged_in() ) return;
|
||||
|
||||
$load_address = woocommerce_get_address_to_edit();
|
||||
|
||||
|
@ -88,9 +85,6 @@ function woocommerce_edit_address() {
|
|||
* Save and and update a billing or shipping address if the
|
||||
* form was submitted through the user account page.
|
||||
*
|
||||
* @todo Address fields should be loaded using the array defined in
|
||||
* the checkout class.
|
||||
*
|
||||
* @package WooCommerce
|
||||
* @since 1.4
|
||||
*/
|
||||
|
@ -187,10 +181,7 @@ function woocommerce_get_address_to_edit() {
|
|||
function woocommerce_change_password() {
|
||||
global $woocommerce;
|
||||
|
||||
if ( ! is_user_logged_in() ) :
|
||||
wp_safe_redirect( get_permalink( woocommerce_get_page_id('myaccount') ) );
|
||||
exit;
|
||||
endif;
|
||||
if ( ! is_user_logged_in() ) return;
|
||||
|
||||
woocommerce_get_template( 'myaccount/change-password.php' );
|
||||
}
|
||||
|
@ -246,18 +237,15 @@ add_action( 'template_redirect', 'woocommerce_save_password' );
|
|||
function woocommerce_view_order() {
|
||||
global $woocommerce;
|
||||
|
||||
if ( ! is_user_logged_in() ) :
|
||||
wp_safe_redirect( get_permalink( woocommerce_get_page_id('myaccount') ) );
|
||||
exit;
|
||||
endif;
|
||||
if ( ! is_user_logged_in() ) return;
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
$order_id = (isset($_GET['order'])) ? $_GET['order'] : 0;
|
||||
$order = new woocommerce_order( $order_id );
|
||||
|
||||
|
||||
if ( $order_id==0 || $order->user_id != $user_id ) :
|
||||
wp_safe_redirect( get_permalink( woocommerce_get_page_id('myaccount') ) );
|
||||
exit;
|
||||
echo '<div class="woocommerce_error">' . __('Invalid order.', 'woocommerce') . ' <a href="'.get_permalink( woocommerce_get_page_id('myaccount') ).'">'. __('My Account →', 'woocommerce') .'</a>' . '</div>';
|
||||
return;
|
||||
endif;
|
||||
|
||||
$status = get_term_by('slug', $order->status, 'shop_order_status');
|
||||
|
|
|
@ -34,40 +34,6 @@ function woocommerce_pay() {
|
|||
if ($order->billing_state) $woocommerce->customer->set_state( $order->billing_state );
|
||||
if ($order->billing_postcode) $woocommerce->customer->set_postcode( $order->billing_postcode );
|
||||
|
||||
// Pay form was posted - process payment
|
||||
if (isset($_POST['pay']) && $woocommerce->verify_nonce('pay')) :
|
||||
|
||||
// Update payment method
|
||||
if ($order->order_total > 0 ) :
|
||||
$payment_method = woocommerce_clean($_POST['payment_method']);
|
||||
|
||||
$available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
|
||||
|
||||
// Update meta
|
||||
update_post_meta( $order_id, '_payment_method', $payment_method);
|
||||
if (isset($available_gateways) && isset($available_gateways[$payment_method])) :
|
||||
$payment_method_title = $available_gateways[$payment_method]->title;
|
||||
endif;
|
||||
update_post_meta( $order_id, '_payment_method_title', $payment_method_title);
|
||||
|
||||
$result = $available_gateways[$payment_method]->process_payment( $order_id );
|
||||
|
||||
// Redirect to success/confirmation/payment page
|
||||
if ($result['result']=='success') :
|
||||
wp_redirect( $result['redirect'] );
|
||||
exit;
|
||||
endif;
|
||||
else :
|
||||
|
||||
// No payment was required for order
|
||||
$order->payment_complete();
|
||||
wp_safe_redirect( get_permalink(woocommerce_get_page_id('thanks')) );
|
||||
exit;
|
||||
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
||||
// Show form
|
||||
woocommerce_get_template('checkout/pay_for_order.php');
|
||||
|
||||
|
@ -124,16 +90,16 @@ function woocommerce_pay() {
|
|||
|
||||
else :
|
||||
|
||||
wp_safe_redirect( get_permalink(woocommerce_get_page_id('myaccount')) );
|
||||
exit;
|
||||
$woocommerce->add_error( __('Your order has already been paid for. Please contact us if you need assistance.', 'woocommerce') );
|
||||
$woocommerce->show_messages();
|
||||
|
||||
endif;
|
||||
|
||||
else :
|
||||
|
||||
wp_safe_redirect( get_permalink(woocommerce_get_page_id('myaccount')) );
|
||||
exit;
|
||||
|
||||
$woocommerce->add_error( __('Invalid order.', 'woocommerce') );
|
||||
$woocommerce->show_messages();
|
||||
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
|
|
@ -20,6 +20,8 @@ function get_woocommerce_thankyou( $atts ) {
|
|||
function woocommerce_thankyou( $atts ) {
|
||||
global $woocommerce, $order;
|
||||
|
||||
$order = false;
|
||||
|
||||
// Pay for order after checkout step
|
||||
if (isset($_GET['order'])) $order_id = $_GET['order']; else $order_id = 0;
|
||||
if (isset($_GET['key'])) $order_key = $_GET['key']; else $order_key = '';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php global $woocommerce, $woocommerce_checkout; ?>
|
||||
<?php global $woocommerce; $woocommerce_checkout = $woocommerce->checkout(); ?>
|
||||
|
||||
<?php $woocommerce->show_messages(); ?>
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
|
||||
<div class="form-row">
|
||||
<?php $woocommerce->nonce_field('pay')?>
|
||||
<input type="submit" class="button-alt" name="pay" id="place_order" value="<?php _e('Pay for order', 'woocommerce'); ?>" />
|
||||
<input type="submit" class="button alt" name="woocommerce_pay" id="place_order" value="<?php _e('Pay for order', 'woocommerce'); ?>" />
|
||||
|
||||
</div>
|
||||
|
||||
|
|
|
@ -226,13 +226,13 @@
|
|||
|
||||
<div class="form-row">
|
||||
|
||||
<noscript><?php _e('Since your browser does not support JavaScript, or it is disabled, please ensure you click the <em>Update Totals</em> button before placing your order. You may be charged more than the amount stated above if you fail to do so.', 'woocommerce'); ?><br/><input type="submit" class="button-alt" name="update_totals" value="<?php _e('Update totals', 'woocommerce'); ?>" /></noscript>
|
||||
<noscript><?php _e('Since your browser does not support JavaScript, or it is disabled, please ensure you click the <em>Update Totals</em> button before placing your order. You may be charged more than the amount stated above if you fail to do so.', 'woocommerce'); ?><br/><input type="submit" class="button-alt" name="woocommerce_checkout_update_totals" value="<?php _e('Update totals', 'woocommerce'); ?>" /></noscript>
|
||||
|
||||
<?php $woocommerce->nonce_field('process_checkout')?>
|
||||
|
||||
<?php do_action( 'woocommerce_review_order_before_submit' ); ?>
|
||||
|
||||
<input type="submit" class="button alt" name="place_order" id="place_order" value="<?php echo apply_filters('woocommerce_order_button_text', __('Place order', 'woocommerce')); ?>" />
|
||||
<input type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="<?php echo apply_filters('woocommerce_order_button_text', __('Place order', 'woocommerce')); ?>" />
|
||||
|
||||
<?php if (woocommerce_get_page_id('terms')>0) : ?>
|
||||
<p class="form-row terms">
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php if (!defined('ABSPATH')) exit; ?>
|
||||
|
||||
<?php global $order, $woocommerce; ?>
|
||||
<?php global $order; ?>
|
||||
|
||||
<?php do_action('woocommerce_email_header'); ?>
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ function woocommerce_ajax_update_order_review() {
|
|||
if (!defined('WOOCOMMERCE_CHECKOUT')) define('WOOCOMMERCE_CHECKOUT', true);
|
||||
|
||||
if (sizeof($woocommerce->cart->get_cart())==0) :
|
||||
echo '<p class="error">'.__('Sorry, your session has expired.', 'woocommerce').' <a href="'.home_url().'">'.__('Return to homepage →', 'woocommerce').'</a></p>';
|
||||
echo '<div class="woocommerce_error">'.__('Sorry, your session has expired.', 'woocommerce').' <a href="'.home_url().'">'.__('Return to homepage →', 'woocommerce').'</a></div>';
|
||||
die();
|
||||
endif;
|
||||
|
||||
|
@ -161,8 +161,8 @@ function woocommerce_ajax_add_to_cart() {
|
|||
add_action('wp_ajax_woocommerce-checkout', 'woocommerce_process_checkout');
|
||||
add_action('wp_ajax_nopriv_woocommerce-checkout', 'woocommerce_process_checkout');
|
||||
|
||||
function woocommerce_process_checkout () {
|
||||
global $woocommerce, $woocommerce_checkout;
|
||||
function woocommerce_process_checkout() {
|
||||
global $woocommerce;
|
||||
|
||||
$woocommerce_checkout = $woocommerce->checkout();
|
||||
$woocommerce_checkout->process_checkout();
|
||||
|
|
|
@ -27,7 +27,7 @@ function woocommerce_mail( $to, $subject, $message, $headers = "Content-Type: te
|
|||
**/
|
||||
if (!function_exists('woocommerce_get_page_id')) {
|
||||
function woocommerce_get_page_id( $page ) {
|
||||
return (int) apply_filters('woocommerce_get_' . $page . '_page_id', get_option('woocommerce_' . $page . '_page_id'));
|
||||
return apply_filters('woocommerce_get_' . $page . '_page_id', get_option('woocommerce_' . $page . '_page_id'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,6 @@ if (!function_exists('is_checkout')) {
|
|||
if (!function_exists('is_account_page')) {
|
||||
function is_account_page() {
|
||||
if ( is_page(woocommerce_get_page_id('myaccount')) || is_page(woocommerce_get_page_id('edit_address')) || is_page(woocommerce_get_page_id('view_order')) || is_page(woocommerce_get_page_id('change_password')) ) return true; else return false;
|
||||
return is_page(woocommerce_get_page_id('myaccount'));
|
||||
}
|
||||
}
|
||||
if (!function_exists('is_ajax')) {
|
||||
|
|
|
@ -10,13 +10,35 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* When default permalinks are enabled, redirect shop page to post type archive url
|
||||
* Handle redirects before content is output - hooked into template_redirect so is_page works
|
||||
**/
|
||||
function woocommerce_shop_page_archive_redirect() {
|
||||
function woocommerce_redirects() {
|
||||
global $woocommerce;
|
||||
|
||||
// When default permalinks are enabled, redirect shop page to post type archive url
|
||||
if ( isset($_GET['page_id']) && get_option( 'permalink_structure' )=="" && $_GET['page_id'] == woocommerce_get_page_id('shop') ) :
|
||||
wp_safe_redirect( get_post_type_archive_link('product') );
|
||||
exit;
|
||||
endif;
|
||||
|
||||
// When on the checkout with an empty cart, redirect to cart page
|
||||
if (is_page(woocommerce_get_page_id('checkout')) && sizeof($woocommerce->cart->get_cart())==0) :
|
||||
wp_redirect(get_permalink(woocommerce_get_page_id('cart')));
|
||||
exit;
|
||||
endif;
|
||||
|
||||
// When on pay page with no query string, redirect to checkout
|
||||
if (is_page(woocommerce_get_page_id('pay')) && !isset($_GET['order'])) :
|
||||
wp_redirect(get_permalink(woocommerce_get_page_id('checkout')));
|
||||
exit;
|
||||
endif;
|
||||
|
||||
// My account page redirects (logged out)
|
||||
if (!is_user_logged_in() && ( is_page(woocommerce_get_page_id('edit_address')) || is_page(woocommerce_get_page_id('view_order')) || is_page(woocommerce_get_page_id('change_password')) )) :
|
||||
wp_redirect(get_permalink(woocommerce_get_page_id('myaccount')));
|
||||
exit;
|
||||
endif;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -338,7 +360,7 @@ function woocommerce_add_to_cart_message() {
|
|||
$woocommerce->add_message( sprintf('<a href="%s" class="button">%s</a> %s', $return_to, __('Continue Shopping →', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') ));
|
||||
|
||||
else :
|
||||
$woocommerce->add_message( sprintf('<a href="%s" class="button">%s</a> %s', $return_to, __('View Cart →', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') ));
|
||||
$woocommerce->add_message( sprintf('<a href="%s" class="button">%s</a> %s', get_permalink(woocommerce_get_page_id('cart')), __('View Cart →', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') ));
|
||||
endif;
|
||||
}
|
||||
|
||||
|
@ -380,6 +402,81 @@ function woocommerce_clear_cart_after_payment() {
|
|||
endif;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process the checkout form
|
||||
**/
|
||||
function woocommerce_checkout_action() {
|
||||
global $woocommerce;
|
||||
|
||||
if (isset($_POST['woocommerce_checkout_place_order']) || isset($_POST['woocommerce_checkout_update_totals'])) :
|
||||
|
||||
if (sizeof($woocommerce->cart->get_cart())==0) :
|
||||
wp_redirect(get_permalink(woocommerce_get_page_id('cart')));
|
||||
exit;
|
||||
endif;
|
||||
|
||||
$woocommerce_checkout = $woocommerce->checkout();
|
||||
$woocommerce_checkout->process_checkout();
|
||||
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the pay form
|
||||
**/
|
||||
function woocommerce_pay_action() {
|
||||
global $woocommerce;
|
||||
|
||||
if (isset($_POST['woocommerce_pay']) && $woocommerce->verify_nonce('pay')) :
|
||||
|
||||
// Pay for existing order
|
||||
$order_key = urldecode( $_GET['order'] );
|
||||
$order_id = (int) $_GET['order_id'];
|
||||
$order = new woocommerce_order( $order_id );
|
||||
|
||||
if ($order->id == $order_id && $order->order_key == $order_key && in_array($order->status, array('pending', 'failed'))) :
|
||||
|
||||
// Set customer location to order location
|
||||
if ($order->billing_country) $woocommerce->customer->set_country( $order->billing_country );
|
||||
if ($order->billing_state) $woocommerce->customer->set_state( $order->billing_state );
|
||||
if ($order->billing_postcode) $woocommerce->customer->set_postcode( $order->billing_postcode );
|
||||
|
||||
// Update payment method
|
||||
if ($order->order_total > 0 ) :
|
||||
$payment_method = woocommerce_clean($_POST['payment_method']);
|
||||
|
||||
$available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
|
||||
|
||||
// Update meta
|
||||
update_post_meta( $order_id, '_payment_method', $payment_method);
|
||||
if (isset($available_gateways) && isset($available_gateways[$payment_method])) :
|
||||
$payment_method_title = $available_gateways[$payment_method]->title;
|
||||
endif;
|
||||
update_post_meta( $order_id, '_payment_method_title', $payment_method_title);
|
||||
|
||||
$result = $available_gateways[$payment_method]->process_payment( $order_id );
|
||||
|
||||
// Redirect to success/confirmation/payment page
|
||||
if ($result['result']=='success') :
|
||||
wp_redirect( $result['redirect'] );
|
||||
exit;
|
||||
endif;
|
||||
else :
|
||||
|
||||
// No payment was required for order
|
||||
$order->payment_complete();
|
||||
wp_safe_redirect( get_permalink(woocommerce_get_page_id('thanks')) );
|
||||
exit;
|
||||
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
||||
endif;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process the login form
|
||||
**/
|
||||
|
|
|
@ -39,7 +39,6 @@ add_action( 'woocommerce_before_subcategory_title', 'woocommerce_subcategory_thu
|
|||
|
||||
/* Before Single Products */
|
||||
add_action( 'woocommerce_before_single_product', array(&$woocommerce, 'show_messages'), 10 );
|
||||
add_action( 'woocommerce_before_single_product', 'woocommerce_check_product_visibility', 10);
|
||||
|
||||
/* Before Single Products Summary Div */
|
||||
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20);
|
||||
|
@ -97,7 +96,7 @@ add_action( 'woocommerce_thankyou', 'woocommerce_order_details_table', 10 );
|
|||
/** Store Event Hooks *****************************************************/
|
||||
|
||||
/* Shop Page Handling and Support */
|
||||
add_action( 'init', 'woocommerce_shop_page_archive_redirect' );
|
||||
add_action( 'template_redirect', 'woocommerce_redirects' );
|
||||
add_filter( 'wp_nav_menu_objects', 'woocommerce_nav_menu_item_classes', 2, 20 );
|
||||
add_action( 'wp', 'woocommerce_front_page_archive_paging_fix', 1 );
|
||||
add_action( 'loop_start', 'woocommerce_front_page_archive', 1 );
|
||||
|
@ -118,6 +117,10 @@ add_action( 'init', 'woocommerce_update_catalog_ordering' );
|
|||
add_action( 'init', 'woocommerce_update_cart_action' );
|
||||
add_action( 'init', 'woocommerce_add_to_cart_action' );
|
||||
|
||||
/* Checkout Actions */
|
||||
add_action( 'init', 'woocommerce_checkout_action' );
|
||||
add_action( 'init', 'woocommerce_pay_action' );
|
||||
|
||||
/* Login and Registration */
|
||||
add_action( 'init', 'woocommerce_process_login' );
|
||||
add_action( 'init', 'woocommerce_process_coupon_form' );
|
||||
|
|
|
@ -182,17 +182,6 @@ if (!function_exists('woocommerce_get_product_thumbnail')) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check product visibility in loop
|
||||
**/
|
||||
if (!function_exists('woocommerce_check_product_visibility')) {
|
||||
function woocommerce_check_product_visibility() {
|
||||
global $post, $product;
|
||||
if (!$product->is_visible( true ) && $post->post_parent > 0) : wp_safe_redirect(get_permalink($post->post_parent)); exit; endif;
|
||||
if (!$product->is_visible( true )) : wp_safe_redirect(home_url()); exit; endif;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pagination
|
||||
**/
|
||||
|
|
|
@ -52,6 +52,7 @@ class woocommerce {
|
|||
var $countries;
|
||||
var $validation;
|
||||
var $woocommerce_email;
|
||||
var $checkout;
|
||||
|
||||
/** Taxonomies ************************************************************/
|
||||
|
||||
|
@ -285,7 +286,7 @@ class woocommerce {
|
|||
|
||||
// Init styles
|
||||
if (!is_admin()) $this->init_styles();
|
||||
|
||||
|
||||
do_action( 'woocommerce_init' );
|
||||
}
|
||||
|
||||
|
@ -890,8 +891,12 @@ class woocommerce {
|
|||
* Get Checkout Class
|
||||
*/
|
||||
function checkout() {
|
||||
if ( !class_exists('woocommerce_checkout') ) include( 'classes/checkout.class.php' );
|
||||
return new woocommerce_checkout();
|
||||
if ( !class_exists('woocommerce_checkout') ) :
|
||||
include( 'classes/checkout.class.php' );
|
||||
$this->checkout = new woocommerce_checkout();
|
||||
endif;
|
||||
|
||||
return $this->checkout;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue