is_modern_checkout_layout( $checkout_id ) ) {
$checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' );
add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'customer_info_parent_wrapper_start' ), 20, 1 );
add_action( 'woocommerce_checkout_billing', array( $this, 'add_custom_billing_email_field' ), 9, 1 );
add_action( 'cartflows_woocommerce_review_order_before_payment', array( $this, 'display_custom_payment_heading' ), 12 );
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form', 10 );
add_action( 'woocommerce_checkout_after_customer_details', array( $this, 'customer_info_parent_wrapper_close' ), 99, 1 );
/* Add the collapsable order review section at the top of Checkout form */
add_action( 'woocommerce_before_checkout_form', array( $this, 'add_custom_collapsed_order_review_table' ), 8 );
// Re-arrange the position of payment section only for two column layout of modern checkout & not for one column.
if ( 'modern-checkout' === $checkout_layout ) {
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
add_action( 'cartflows_checkout_after_modern_checkout_layout', 'woocommerce_checkout_payment', 21 );
}
}
}
/**
* Return true if checkout layout skin is conditional checkout.
*
* @param int $checkout_id Checkout ID.
*
* @return bool
*/
public function is_modern_checkout_layout( $checkout_id = '' ) {
global $post;
$is_modern_checkout = false;
if ( ! empty( $post ) && empty( $checkout_id ) ) {
$checkout_id = $post->ID;
}
if ( ! empty( $checkout_id ) ) {
// Get checkout layout skin.
$checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' );
if ( 'modern-checkout' === $checkout_layout || 'modern-one-column' === $checkout_layout ) {
$is_modern_checkout = true;
}
}
return $is_modern_checkout;
}
/**
* Add Customer Information Section.
*
* @param int $checkout_id checkout ID.
*
* @return void
*/
public function customer_info_parent_wrapper_start( $checkout_id ) {
do_action( 'cartflows_checkout_before_modern_checkout_layout', $checkout_id );
echo '
';
}
/**
* Add Custom Email Field.
*
* @return void
*/
public function add_custom_billing_email_field() {
$checkout_id = _get_wcf_checkout_id();
if ( ! $checkout_id ) {
$checkout_id = isset( $_GET['wcf_checkout_id'] ) && ! empty( $_GET['wcf_checkout_id'] ) ? intval( wp_unslash( $_GET['wcf_checkout_id'] ) ) : 0; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
}
$default = '';
if ( is_auto_prefill_checkout_fields_enabled() && ( isset( $_GET['billing_email'] ) && ! empty( $_GET['billing_email'] ) ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
$default = sanitize_email( wp_unslash( $_GET['billing_email'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
}
$lost_password_url = esc_url( wp_lostpassword_url() );
$current_user_name = wp_get_current_user()->display_name;
$current_user_email = wp_get_current_user()->user_email;
$is_allow_login = 'yes' === get_option( 'woocommerce_enable_checkout_login_reminder' );
$fields_skins = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-fields-skins' );
$required_mark = 'modern-label' === $fields_skins ? '*' : '';
?>
', '' ) ); ?>
'email',
'class' => array( 'form-row-fill' ),
'required' => true,
'label' => __( 'Email Address', 'cartflows' ),
'default' => $default,
/* translators: %s: asterisk mark */
'placeholder' => sprintf( __( 'Email Address %s', 'cartflows' ), $required_mark ),
'autocomplete' => 'email username',
)
);
if ( 'yes' === get_option( 'woocommerce_enable_checkout_login_reminder' ) ) {
?>
'password',
'class' => array( 'form-row-fill', 'wcf-password-field' ),
'required' => true,
'label' => __( 'Password', 'cartflows' ),
/* translators: %s: asterisk mark */
'placeholder' => sprintf( __( 'Password %s', 'cartflows' ), $required_mark ),
)
);
?>
" . esc_html( __( 'Login is optional, you can continue with your order below.', 'cartflows' ) ) . '';
}
?>
'text',
'class' => array( 'form-row-fill' ),
'id' => 'account_username',
'required' => true,
'label' => __( 'Account username', 'cartflows' ),
/* translators: %s: asterisk mark */
'placeholder' => sprintf( __( 'Account username %s', 'cartflows' ), $required_mark ),
)
);
}
if ( 'no' === get_option( 'woocommerce_registration_generate_password' ) ) {
woocommerce_form_field(
'account_password',
array(
'type' => 'password',
'id' => 'account_password',
'class' => array( 'form-row-fill' ),
'required' => true,
'label' => __( 'Create account password', 'cartflows' ),
/* translators: %s: asterisk mark */
'placeholder' => sprintf( __( 'Create account password %s', 'cartflows' ), $required_mark ),
)
);
}
?>
';
}
/**
* Customized order review section used to display in modern checkout responsive devices.
*
* @return void
*/
public function add_custom_collapsed_order_review_table() {
include CARTFLOWS_CHECKOUT_DIR . 'templates/checkout/collapsed-order-summary.php';
}
/**
* Prefill the checkout fields if available in url.
*
* @param array $checkout_fields checkout fields array.
*/
public function unset_fields_for_modern_checkout( $checkout_fields ) {
$checkout_id = _get_wcf_checkout_id();
if ( ! $checkout_id ) {
$checkout_id = wcf()->utils->get_checkout_id_from_post_data();
}
if ( ! _is_wcf_checkout_type() || ! $this->is_modern_checkout_layout( $checkout_id ) ) {
return $checkout_fields;
}
// No nonce verification required as it is called on woocommerce action.
if ( wp_doing_ajax() || ( isset( $_GET['wc-ajax'] ) && 'checkout' === $_GET['wc-ajax'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
return $checkout_fields;
}
// Unset defalut billing email from Billing Details.
unset( $checkout_fields['billing']['billing_email'] );
unset( $checkout_fields['account']['account_username'] );
unset( $checkout_fields['account']['account_password'] );
return $checkout_fields;
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
Cartflows_Modern_Checkout::get_instance();