Load options in checkout class and ensure hooks are available to change the options. Closes #1950.
This commit is contained in:
parent
8044d8c2af
commit
bfcb3ec1e9
|
@ -20,6 +20,9 @@ class WC_Checkout {
|
|||
/** @var bool Whether or not the user must create an account to checkout. */
|
||||
var $must_create_account;
|
||||
|
||||
/** @var bool Whether or not signups are allowed. */
|
||||
var $enable_signup;
|
||||
|
||||
/** @var bool True when the user is creating an account. */
|
||||
var $creating_account;
|
||||
|
||||
|
@ -32,11 +35,13 @@ class WC_Checkout {
|
|||
function __construct () {
|
||||
global $woocommerce;
|
||||
|
||||
add_action('woocommerce_checkout_process',array(&$this,'checkout_process'));
|
||||
add_action('woocommerce_checkout_billing',array(&$this,'checkout_form_billing'));
|
||||
add_action('woocommerce_checkout_shipping',array(&$this,'checkout_form_shipping'));
|
||||
add_action( 'woocommerce_checkout_process', array( &$this,'checkout_process' ) );
|
||||
add_action( 'woocommerce_checkout_billing', array( &$this,'checkout_form_billing' ) );
|
||||
add_action( 'woocommerce_checkout_shipping', array( &$this,'checkout_form_shipping' ) );
|
||||
|
||||
$this->must_create_account = get_option('woocommerce_enable_guest_checkout') == 'yes' || is_user_logged_in() ? false : true;
|
||||
$this->enable_signup = get_option( 'woocommerce_enable_signup_and_login_from_checkout' ) == 'yes' ? true : false;
|
||||
$this->enable_guest_checkout = get_option( 'woocommerce_enable_guest_checkout' ) == 'yes' ? true : false;
|
||||
$this->must_create_account = $this->enable_guest_checkout || is_user_logged_in() ? false : true;
|
||||
|
||||
// Define all Checkout fields
|
||||
$this->checkout_fields['billing'] = $woocommerce->countries->get_address_fields( $this->get_value('billing_country'), 'billing_' );
|
||||
|
@ -75,7 +80,10 @@ class WC_Checkout {
|
|||
'placeholder' => _x('Notes about your order, e.g. special notes for delivery.', 'placeholder', 'woocommerce')
|
||||
)
|
||||
);
|
||||
$this->checkout_fields = apply_filters('woocommerce_checkout_fields', $this->checkout_fields);
|
||||
|
||||
$this->checkout_fields = apply_filters( 'woocommerce_checkout_fields', $this->checkout_fields );
|
||||
|
||||
do_action( 'woocommerce_checkout_init', $this );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ function get_woocommerce_checkout( $atts ) {
|
|||
function woocommerce_checkout( $atts ) {
|
||||
global $woocommerce;
|
||||
|
||||
// Prevent cache
|
||||
$woocommerce->nocache();
|
||||
|
||||
// Show non-cart errors
|
||||
|
@ -47,9 +48,12 @@ function woocommerce_checkout( $atts ) {
|
|||
// Check cart contents for errors
|
||||
do_action('woocommerce_check_cart_items');
|
||||
|
||||
// Get checkout object
|
||||
$checkout = $woocommerce->checkout();
|
||||
|
||||
if ( empty( $_POST ) && $woocommerce->error_count() > 0 ) {
|
||||
|
||||
woocommerce_get_template('checkout/cart-errors.php');
|
||||
woocommerce_get_template( 'checkout/cart-errors.php', array( 'checkout' => $checkout ) );
|
||||
|
||||
} else {
|
||||
|
||||
|
@ -58,7 +62,7 @@ function woocommerce_checkout( $atts ) {
|
|||
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-checkout.php');
|
||||
woocommerce_get_template( 'checkout/form-checkout.php', array( 'checkout' => $checkout ) );
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ function woocommerce_pay() {
|
|||
if ($order->billing_postcode) $woocommerce->customer->set_postcode( $order->billing_postcode );
|
||||
|
||||
// Show form
|
||||
woocommerce_get_template('checkout/form-pay.php', array('order' => $order));
|
||||
woocommerce_get_template( 'checkout/form-pay.php', array( 'order' => $order ) );
|
||||
|
||||
elseif (!in_array($order->status, array('pending', 'failed'))) :
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @author WooThemes
|
||||
* @package WooCommerce/Templates
|
||||
* @version 1.6.4
|
||||
* @version 2.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
@ -22,7 +22,7 @@ global $woocommerce;
|
|||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php do_action('woocommerce_before_checkout_billing_form', $checkout); ?>
|
||||
<?php do_action('woocommerce_before_checkout_billing_form', $checkout ); ?>
|
||||
|
||||
<?php foreach ($checkout->checkout_fields['billing'] as $key => $field) : ?>
|
||||
|
||||
|
@ -30,11 +30,13 @@ global $woocommerce;
|
|||
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php do_action('woocommerce_after_checkout_billing_form', $checkout); ?>
|
||||
<?php do_action('woocommerce_after_checkout_billing_form', $checkout ); ?>
|
||||
|
||||
<?php if (!is_user_logged_in() && get_option('woocommerce_enable_signup_and_login_from_checkout')=="yes") : ?>
|
||||
|
||||
<?php if (get_option('woocommerce_enable_guest_checkout')=='yes') : ?>
|
||||
|
||||
<?php if ( ! is_user_logged_in() && $checkout->enable_signup ) : ?>
|
||||
|
||||
<?php if ( $checkout->enable_guest_checkout ) : ?>
|
||||
|
||||
<p class="form-row">
|
||||
<input class="input-checkbox" id="createaccount" <?php checked($checkout->get_value('createaccount'), true) ?> type="checkbox" name="createaccount" value="1" /> <label for="createaccount" class="checkbox"><?php _e( 'Create an account?', 'woocommerce' ); ?></label>
|
||||
|
|
|
@ -4,57 +4,56 @@
|
|||
*
|
||||
* @author WooThemes
|
||||
* @package WooCommerce/Templates
|
||||
* @version 1.6.4
|
||||
* @version 2.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
global $woocommerce; $woocommerce_checkout = $woocommerce->checkout();
|
||||
?>
|
||||
global $woocommerce;
|
||||
|
||||
<?php $woocommerce->show_messages(); ?>
|
||||
$woocommerce->show_messages();
|
||||
|
||||
<?php do_action('woocommerce_before_checkout_form');
|
||||
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()) :
|
||||
echo apply_filters('woocommerce_checkout_must_be_logged_in_message', __( 'You must be logged in to checkout.', 'woocommerce' ));
|
||||
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;
|
||||
endif;
|
||||
}
|
||||
|
||||
// filter hook for include new pages inside the payment method
|
||||
$get_checkout_url = apply_filters( 'woocommerce_get_checkout_url', $woocommerce->cart->get_checkout_url() ); ?>
|
||||
|
||||
<form name="checkout" method="post" class="checkout" action="<?php echo esc_url( $get_checkout_url ); ?>">
|
||||
|
||||
<?php if ( sizeof( $woocommerce_checkout->checkout_fields ) > 0 ) : ?>
|
||||
<?php if ( sizeof( $checkout->checkout_fields ) > 0 ) : ?>
|
||||
|
||||
<?php do_action( 'woocommerce_checkout_before_customer_details'); ?>
|
||||
<?php do_action( 'woocommerce_checkout_before_customer_details' ); ?>
|
||||
|
||||
<div class="col2-set" id="customer_details">
|
||||
|
||||
<div class="col-1">
|
||||
|
||||
<?php do_action('woocommerce_checkout_billing'); ?>
|
||||
<?php do_action( 'woocommerce_checkout_billing' ); ?>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-2">
|
||||
|
||||
<?php do_action('woocommerce_checkout_shipping'); ?>
|
||||
<?php do_action( 'woocommerce_checkout_shipping' ); ?>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<?php do_action( 'woocommerce_checkout_after_customer_details'); ?>
|
||||
<?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_order_review'); ?>
|
||||
<?php do_action( 'woocommerce_checkout_order_review' ); ?>
|
||||
|
||||
</form>
|
||||
|
||||
<?php do_action('woocommerce_after_checkout_form'); ?>
|
||||
<?php do_action( 'woocommerce_after_checkout_form' ); ?>
|
|
@ -4,17 +4,23 @@
|
|||
*
|
||||
* @author WooThemes
|
||||
* @package WooCommerce/Templates
|
||||
* @version 1.6.4
|
||||
* @version 2.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( is_user_logged_in() ) return;
|
||||
if ( get_option('woocommerce_enable_signup_and_login_from_checkout') == "no" ) return;
|
||||
if ( is_user_logged_in() || ! $checkout->enable_signup ) return;
|
||||
|
||||
$info_message = apply_filters('woocommerce_checkout_login_message', __( 'Already registered?', 'woocommerce' ));
|
||||
$info_message = apply_filters( 'woocommerce_checkout_login_message', __( 'Already registered?', 'woocommerce' ) );
|
||||
?>
|
||||
|
||||
<p class="woocommerce_info"><?php echo esc_html( $info_message ); ?> <a href="#" class="showlogin"><?php _e( 'Click here to login', 'woocommerce' ); ?></a></p>
|
||||
|
||||
<?php woocommerce_login_form( array( 'message' => __( 'If you have shopped with us before, please enter your details in the boxes below. If you are a new customer please proceed to the Billing & Shipping section.', 'woocommerce' ), 'redirect' => get_permalink(woocommerce_get_page_id('checkout')) ) ); ?>
|
||||
<?php
|
||||
woocommerce_login_form(
|
||||
array(
|
||||
'message' => __( 'If you have shopped with us before, please enter your details in the boxes below. If you are a new customer please proceed to the Billing & Shipping section.', 'woocommerce' ),
|
||||
'redirect' => get_permalink( woocommerce_get_page_id( 'checkout') )
|
||||
)
|
||||
);
|
||||
?>
|
|
@ -30,7 +30,7 @@ $available_methods = $woocommerce->shipping->get_available_shipping_methods();
|
|||
<td><?php echo $woocommerce->cart->get_cart_subtotal(); ?></td>
|
||||
</tr>
|
||||
|
||||
<?php if ($woocommerce->cart->get_discounts_before_tax()) : ?>
|
||||
<?php if ( $woocommerce->cart->get_discounts_before_tax() ) : ?>
|
||||
|
||||
<tr class="discount">
|
||||
<th colspan="2"><?php _e( 'Cart Discount', 'woocommerce' ); ?></th>
|
||||
|
@ -241,7 +241,7 @@ $available_methods = $woocommerce->shipping->get_available_shipping_methods();
|
|||
<?php if (woocommerce_get_page_id('terms')>0) : ?>
|
||||
<p class="form-row terms">
|
||||
<label for="terms" class="checkbox"><?php _e( 'I have read and accept the', 'woocommerce' ); ?> <a href="<?php echo esc_url( get_permalink(woocommerce_get_page_id('terms')) ); ?>" target="_blank"><?php _e( 'terms & conditions', 'woocommerce' ); ?></a></label>
|
||||
<input type="checkbox" class="input-checkbox" name="terms" <?php if (isset($_POST['terms'])) echo 'checked="checked"'; ?> id="terms" />
|
||||
<input type="checkbox" class="input-checkbox" name="terms" <?php checked( isset( $_POST['terms'] ), true ); ?> id="terms" />
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
|
|
|
@ -155,10 +155,10 @@ function woocommerce_ajax_update_order_review() {
|
|||
die();
|
||||
}
|
||||
|
||||
do_action('woocommerce_checkout_update_order_review', $_POST['post_data']);
|
||||
do_action( 'woocommerce_checkout_update_order_review', $_POST['post_data'] );
|
||||
|
||||
$woocommerce->session->chosen_shipping_method = empty( $_POST['shipping_method'] ) ? '' : $_POST['shipping_method'];
|
||||
$woocommerce->session->chosen_payment_method = empty( $_POST['payment_method'] ) ? '' : $_POST['payment_method'];
|
||||
$woocommerce->session->chosen_payment_method = empty( $_POST['payment_method'] ) ? '' : $_POST['payment_method'];
|
||||
|
||||
if ( isset( $_POST['country'] ) )
|
||||
$woocommerce->customer->set_country( $_POST['country'] );
|
||||
|
@ -198,7 +198,7 @@ function woocommerce_ajax_update_order_review() {
|
|||
|
||||
$woocommerce->cart->calculate_totals();
|
||||
|
||||
do_action('woocommerce_checkout_order_review'); // Display review order table
|
||||
do_action( 'woocommerce_checkout_order_review' ); // Display review order table
|
||||
|
||||
die();
|
||||
}
|
||||
|
|
|
@ -929,7 +929,9 @@ if ( ! function_exists( 'woocommerce_checkout_login_form' ) ) {
|
|||
* @return void
|
||||
*/
|
||||
function woocommerce_checkout_login_form() {
|
||||
woocommerce_get_template( 'checkout/form-login.php' );
|
||||
global $woocommerce;
|
||||
|
||||
woocommerce_get_template( 'checkout/form-login.php', array( 'checkout' => $woocommerce->checkout() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -968,7 +970,9 @@ if ( ! function_exists( 'woocommerce_order_review' ) ) {
|
|||
* @return void
|
||||
*/
|
||||
function woocommerce_order_review() {
|
||||
woocommerce_get_template( 'checkout/review-order.php' );
|
||||
global $woocommerce;
|
||||
|
||||
woocommerce_get_template( 'checkout/review-order.php', array( 'checkout' => $woocommerce->checkout() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -982,7 +986,9 @@ if ( ! function_exists( 'woocommerce_checkout_coupon_form' ) ) {
|
|||
* @return void
|
||||
*/
|
||||
function woocommerce_checkout_coupon_form() {
|
||||
woocommerce_get_template( 'checkout/form-coupon.php' );
|
||||
global $woocommerce;
|
||||
|
||||
woocommerce_get_template( 'checkout/form-coupon.php', array( 'checkout' => $woocommerce->checkout() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1132,11 +1132,10 @@ class Woocommerce {
|
|||
* @return WC_Checkout
|
||||
*/
|
||||
function checkout() {
|
||||
if ( ! class_exists('WC_Checkout') ) {
|
||||
include( 'classes/class-wc-checkout.php' );
|
||||
if ( ! class_exists( 'WC_Checkout' ) ) {
|
||||
include_once( 'classes/class-wc-checkout.php' );
|
||||
$this->checkout = new WC_Checkout();
|
||||
}
|
||||
|
||||
return $this->checkout;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue