' . $setting['login_toggle_text'] . '', 'notice' ); ?>
' . $setting['coupon_toggle_text'] . '' ), 'notice' ); ?>
checkout();
?>
checkout();
$shipping_needed = WC()->cart->needs_shipping_address();
?>
cart->needs_shipping() || wc_ship_to_billing_address_only() ) : ?>
get_checkout_fields( 'order' );
foreach ( $order_data as $key => $field ) :
?>
get_value( $key ) ); ?>
checkout();
?>
cart->get_cart();
foreach ( $cart_data as $cart_item_key => $cart_item ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_checkout_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
?>
-
get_image(), $cart_item, $cart_item_key );
echo $thumbnail; // phpcs:ignore XSS ok.
?>
get_name(), $cart_item, $cart_item_key ) . ' '; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
' . sprintf( '× %s', $cart_item['quantity'] ) . '', $cart_item, $cart_item_key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
cart->get_product_subtotal( $_product, $cart_item['quantity'] );
echo apply_filters( 'woocommerce_cart_item_subtotal', $product_subtotal, $cart_item, $cart_item_key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
cart->needs_payment() ) {
$available_gateways = WC()->payment_gateways()->get_available_payment_gateways();
WC()->payment_gateways()->set_current_gateway( $available_gateways );
} else {
$available_gateways = array();
}
?>
WC()->checkout(),
'available_gateways' => $available_gateways,
'order_button_text' => apply_filters( 'woocommerce_order_button_text', esc_html( 'Place Order' ) ),
)
);
?>
get_id() !== $order_id || ! hash_equals( $order->get_order_key(), $order_key ) ) {
throw new Exception( __( 'Sorry, this order is invalid and cannot be paid for.', 'uael' ) );
}
if ( ! current_user_can( 'pay_for_order', $order_id ) && ! is_user_logged_in() ) {
echo '' . esc_html__( 'Please log in to your account below to continue to the payment form.', 'uael' ) . '
';
woocommerce_login_form(
array(
'redirect' => $order->get_checkout_payment_url(),
)
);
return;
}
if ( ! $order->get_user_id() && is_user_logged_in() ) {
if ( $order->get_billing_email() !== wp_get_current_user()->user_email ) {
wc_print_notice( __( 'You are paying for a guest order. Please continue with payment only if you recognize this order.', 'uael' ), 'error' );
}
}
if ( ! current_user_can( 'pay_for_order', $order_id ) ) {
throw new Exception( __( 'This order cannot be paid for. Please contact us if you need assistance.', 'uael' ) );
}
if ( ! $order->needs_payment() ) {
/* translators: %s: order status */
throw new Exception( sprintf( __( 'This order’s status is “%s”—it cannot be paid for. Please contact us if you need assistance.', 'uael' ), wc_get_order_status_name( $order->get_status() ) ) );
}
if ( ! $order->has_status( wc_get_is_pending_statuses() ) ) {
$quantities = array();
foreach ( $order->get_items() as $item_key => $item ) {
if ( $item && is_callable( array( $item, 'get_product' ) ) ) {
$product = $item->get_product();
if ( ! $product ) {
continue;
}
$quantities[ $product->get_stock_managed_by_id() ] = isset( $quantities[ $product->get_stock_managed_by_id() ] ) ? $quantities[ $product->get_stock_managed_by_id() ] + $item->get_quantity() : $item->get_quantity();
}
}
foreach ( $order->get_items() as $item_key => $item ) {
if ( $item && is_callable( array( $item, 'get_product' ) ) ) {
$product = $item->get_product();
if ( ! $product ) {
continue;
}
if ( ! apply_filters( 'woocommerce_pay_order_product_in_stock', $product->is_in_stock(), $product, $order ) ) {
/* translators: %s: product name */
throw new Exception( sprintf( __( 'Sorry, "%s" is no longer in stock so this order cannot be paid for. We apologize for any inconvenience caused.', 'uael' ), $product->get_name() ) );
}
if ( ! $product->managing_stock() || $product->backorders_allowed() ) {
continue;
}
$held_stock = ( $hold_stock_minutes > 0 ) ? wc_get_held_stock_quantity( $product, $order->get_id() ) : 0;
$required_stock = $quantities[ $product->get_stock_managed_by_id() ];
if ( ! apply_filters( 'woocommerce_pay_order_product_has_enough_stock', ( $product->get_stock_quantity() >= ( $held_stock + $required_stock ) ), $product, $order ) ) {
/* translators: 1: product name 2: quantity in stock */
throw new Exception( sprintf( __( 'Sorry, we do not have enough "%1$s" in stock to fulfill your order (%2$s available). We apologize for any inconvenience caused.', 'uael' ), $product->get_name(), wc_format_stock_quantity_for_display( $product->get_stock_quantity() - $held_stock, $product ) ) );
}
}
}
}
WC()->customer->set_props(
array(
'billing_country' => $order->get_billing_country() ? $order->get_billing_country() : null,
'billing_state' => $order->get_billing_state() ? $order->get_billing_state() : null,
'billing_postcode' => $order->get_billing_postcode() ? $order->get_billing_postcode() : null,
)
);
WC()->customer->save();
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
if ( count( $available_gateways ) ) {
current( $available_gateways )->set_current();
}
wc_get_template(
'checkout/form-pay.php',
array(
'order' => $order,
'available_gateways' => $available_gateways,
'order_button_text' => apply_filters( 'woocommerce_pay_order_button_text', __( 'Pay for order', 'uael' ) ),
)
);
} catch ( Exception $e ) {
wc_print_notice( $e->getMessage(), 'error' );
}
} elseif ( $order_id ) {
$order_key = isset( $_GET['key'] ) ? wc_clean( wp_unslash( $_GET['key'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, input var ok, CSRF ok.
$order = wc_get_order( $order_id );
if ( $order && $order->get_id() === $order_id && hash_equals( $order->get_order_key(), $order_key ) ) {
if ( $order->needs_payment() ) {
wc_get_template( 'checkout/order-receipt.php', array( 'order' => $order ) );
} else {
/* translators: %s: order status */
wc_print_notice( sprintf( __( 'This order’s status is “%s”—it cannot be paid for. Please contact us if you need assistance.', 'uael' ), wc_get_order_status_name( $order->get_status() ) ), 'error' );
}
} else {
wc_print_notice( __( 'Sorry, this order is invalid and cannot be paid for.', 'uael' ), 'error' );
}
} else {
wc_print_notice( __( 'Invalid order.', 'uael' ), 'error' );
}
do_action( 'after_woocommerce_pay' );
}
/**
* UAEL checkout received order template function.
*
* @param int $order_id Order ID.
*
* @throws \WC_Data_Exception Throws exceptions if any.
* @since 1.31.0
* @access public
*/
public static function uael_received_order( $order_id = 0 ) {
$order = false;
$order_id = apply_filters( 'woocommerce_thankyou_order_id', absint( $order_id ) );
$order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['key'] ) ? '' : wc_clean( wp_unslash( $_GET['key'] ) ) ); // phpcs:ignore
if ( $order_id > 0 ) {
$order = wc_get_order( $order_id );
if ( ! $order || ! hash_equals( $order->get_order_key(), $order_key ) ) {
$order = false;
}
}
unset( WC()->session->order_awaiting_payment );
if ( $order && $order->is_created_via( 'admin' ) ) {
$order->set_customer_ip_address( \WC_Geolocation::get_ip_address() );
$order->save();
}
wc_empty_cart();
wc_get_template( 'checkout/thankyou.php', array( 'order' => $order ) );
}
/**
* Main functions that renders all checkout layouts accordingly.
*
* @since 1.31.0
* @access public
*/
public static function uael_checkout() {
$setting = self::uael_get_woo_checkout_settings();
do_action( 'woocommerce_before_checkout_form_cart_notices' );
if ( WC()->cart->is_empty() && ! is_customize_preview() && apply_filters( 'woocommerce_checkout_redirect_empty_cart', true ) ) {
return;
}
do_action( 'woocommerce_check_cart_items' );
WC()->cart->calculate_totals();
$checkout = WC()->checkout();
if ( empty( $_POST ) && wc_notice_count( 'error' ) > 0 ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
wc_get_template( 'checkout/cart-errors.php', array( 'checkout' => $checkout ) );
wc_clear_notices();
} else {
$non_js_checkout = ! empty( $_POST['woocommerce_checkout_update_totals'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
if ( wc_notice_count( 'error' ) === 0 && $non_js_checkout ) {
wc_add_notice( __( 'The order totals have been updated. Please confirm your order by pressing the "Place order" button at the bottom of the page.', 'uael' ) );
}
switch ( $setting['layout'] ) {
case '1':
echo self::single_column_layout( $checkout ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
break;
case '2':
echo self::two_column_layout( $checkout ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
break;
case '3':
echo self::multistep_layout( $checkout, $setting ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
break;
default:
}
}
}
/**
* Renders the Single column checkout page layout.
*
* @since 1.31.0
* @access public
* @param \WC_Checkout $checkout Main WC_Checkout Instance.
*/
public static function single_column_layout( $checkout ) {
?>
is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in() ) {
?>
is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in() ) {
?>
'',
'icons' => 'uael-step-icon',
'dot' => 'uael-step-dot',
'counter' => 'uael-step-counter',
);
?>
is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in() ) {
?>
cart->calculate_totals();
$checkout = WC()->checkout();
if ( 'yes' !== $setting['additional_info_box'] ) {
add_filter( 'woocommerce_enable_order_notes_field', '__return_false', 9999 );
}
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form', 10 );
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
if ( '1' === $setting['layout'] || '2' === $setting['layout'] || ( '3' === $setting['layout'] && ! $checkout->is_registration_enabled() && $checkout->is_registration_required() ) ) {
add_action( 'woocommerce_before_checkout_form', array( $this, 'uael_login_template' ), 10 );
}
if ( is_user_logged_in() || ( ! ( ! $checkout->is_registration_enabled() && $checkout->is_registration_required() ) ) ) {
add_action( 'woocommerce_before_checkout_form', array( $this, 'uael_coupon_template' ), 10 );
}
$woo_checkout_instance = WC()->checkout();
remove_action( 'woocommerce_checkout_billing', array( $woo_checkout_instance, 'checkout_form_billing' ) );
remove_action( 'woocommerce_checkout_shipping', array( $woo_checkout_instance, 'checkout_form_shipping' ) );
remove_action( 'woocommerce_checkout_billing', array( $woo_checkout_instance, 'checkout_form_shipping' ) );
add_action( 'woocommerce_checkout_billing', array( $this, 'uael_billing_form_template' ), 10 );
add_action( 'woocommerce_checkout_shipping', array( $this, 'uael_shipping_form_template' ), 10 );
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
add_action( 'woocommerce_checkout_order_review', array( $this, 'uael_order_review_template' ), 10 );
add_action( 'woocommerce_checkout_order_review', array( $this, 'uael_checkout_payment_template' ), 20 );
}
}