jQuery(document).ready(function( $ ){ $(".wpmc-nav-wrapper").addClass('woocommerce'); }); jQuery(document).ready(function( $ ){ $( '.woocommerce-checkout' ).on( 'wpmc_after_switching_tab', function() { if ( $('ul.wpmc-tabs-list').data('current-title') === 'review') { $(document.body).trigger("update_checkout"); } }); }); ' . $js . ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } /** * Hook adjustments to themes and plugins. */ public static function after_setup_theme() { $theme = strtolower( get_template() ); /* * Avada theme. */ if ( strpos( $theme, 'avada' ) !== false ) { if ( function_exists( 'avada_woocommerce_before_checkout_form' ) ) { remove_action( 'woocommerce_before_checkout_form', 'avada_woocommerce_before_checkout_form' ); } if ( function_exists( 'avada_woocommerce_checkout_after_customer_details' ) ) { remove_action( 'woocommerce_checkout_after_customer_details', 'avada_woocommerce_checkout_after_customer_details' ); } if ( function_exists( 'avada_woocommerce_checkout_before_customer_details' ) ) { remove_action( 'woocommerce_checkout_before_customer_details', 'avada_woocommerce_checkout_before_customer_details' ); } global $avada_woocommerce; if ( ! empty( $avada_woocommerce ) ) { remove_action( 'woocommerce_before_checkout_form', array( $avada_woocommerce, 'avada_top_user_container' ), 1 ); remove_action( 'woocommerce_before_checkout_form', array( $avada_woocommerce, 'checkout_coupon_form' ), 10 ); remove_action( 'woocommerce_before_checkout_form', array( $avada_woocommerce, 'before_checkout_form' ) ); remove_action( 'woocommerce_after_checkout_form', array( $avada_woocommerce, 'after_checkout_form' ) ); remove_action( 'woocommerce_checkout_before_customer_details', array( $avada_woocommerce, 'checkout_before_customer_details' ) ); remove_action( 'woocommerce_checkout_after_customer_details', array( $avada_woocommerce, 'checkout_after_customer_details' ) ); } } /* * Hestia Pro theme. */ if ( strpos( $theme, 'hestia-pro' ) !== false ) { remove_action( 'woocommerce_before_checkout_form', 'hestia_coupon_after_order_table_js' ); } /* * Astra theme. */ if ( strpos( $theme, 'astra' ) !== false ) { if ( ! defined( 'WC_AMAZON_PAY_VERSION' ) ) { add_filter( 'astra_woo_shop_product_structure_override', '__return_true' ); add_action( 'woocommerce_checkout_shipping', array( WC()->checkout(), 'checkout_form_shipping' ), 20 ); add_action( 'woocommerce_before_shop_loop_item', 'astra_woo_shop_thumbnail_wrap_start', 6 ); add_action( 'woocommerce_before_shop_loop_item', 'woocommerce_show_product_loop_sale_flash', 9 ); add_action( 'woocommerce_after_shop_loop_item', 'astra_woo_shop_thumbnail_wrap_end', 8 ); add_action( 'woocommerce_shop_loop_item_title', 'astra_woo_shop_out_of_stock', 8 ); remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); add_action( 'woocommerce_after_shop_loop_item', 'astra_woo_woocommerce_shop_product_content' ); } add_filter( 'astra_get_option_checkout-layout-type', 'WMSC_Compatibilities::astra_get_option_checkout_layout_type', 10, 3 ); } /** * Porto theme. */ if ( strpos( $theme, 'porto' ) !== false ) { add_filter( 'porto_filter_checkout_version', 'WMSC_Compatibilities::porto_checkout_version' ); } /** * Electro theme. */ if ( strpos( $theme, 'electro' ) !== false ) { remove_action( 'woocommerce_checkout_before_order_review', 'electro_wrap_order_review', 0 ); remove_action( 'woocommerce_checkout_after_order_review', 'electro_wrap_order_review_close', 0 ); } /** * Neve theme. */ if ( strpos( $theme, 'neve' ) !== false ) { add_filter( 'woocommerce_queued_js', 'WMSC_Compatibilities::neve_remove_js' ); } /** * Woodmart theme. */ if ( strpos( $theme, 'woodmart' ) !== false ) { add_filter( 'wmsc_buttons_class', 'WMSC_Compatibilities::woodmart_buttons' ); } /** * Fastland theme. */ if ( strpos( $theme, 'fastland' ) !== false ) { remove_action( 'woocommerce_checkout_after_customer_details', 'fastland_wc_checkout_order_details_wrapper_start', 40 ); remove_action( 'woocommerce_review_order_before_payment', 'fastland_wc_checkout_order_details_wrapper_end' ); } /* * Germanized for WooCommerce plugin. */ if ( class_exists( 'WooCommerce_Germanized' ) ) { remove_action( 'woocommerce_review_order_after_payment', 'woocommerce_gzd_template_render_checkout_checkboxes', 10 ); } /* * Twenty-Twenty Three theme. */ if ( strpos( $theme, 'twentytwentythree' ) !== false || strpos( $theme, 'twentytwentytwo' ) !== false ) { remove_action( 'woocommerce_checkout_before_order_review_heading', array( 'WC_Twenty_Twenty_Three', 'before_order_review' ) ); remove_action( 'woocommerce_checkout_after_order_review', array( 'WC_Twenty_Twenty_Three', 'before_order_review' ) ); remove_action( 'woocommerce_checkout_before_order_review_heading', array( 'WC_Twenty_Twenty_Two', 'before_order_review' ) ); remove_action( 'woocommerce_checkout_after_order_review', array( 'WC_Twenty_Twenty_Two', 'before_order_review' ) ); add_filter( 'wmsc_buttons_class', 'WMSC_Compatibilities::twentytwenty_buttons' ); } } /** * Hook adjustments for themes and plugins. */ public static function wp() { $theme = strtolower( get_template() ); /* * Avada theme. */ if ( strpos( $theme, 'avada' ) !== false ) { $filters_to_remove = array( 'woocommerce_checkout_after_customer_details', 'woocommerce_checkout_before_customer_details', 'woocommerce_before_checkout_form', ); self::remove_filters( $filters_to_remove, 'Avada_WooCommerce' ); global $avada_woocommerce; add_action( 'wpmc_before_tabs', array( $avada_woocommerce, 'avada_top_user_container' ), 1 ); } /* * fuelthemes on codecanyon. */ foreach ( array( 'peakshops', 'revolution', 'theissue', 'werkstatt', 'twofold', 'goodlife', 'voux', 'notio', 'north' ) as $_theme ) { if ( strpos( $theme, $_theme ) === false ) { continue; } $filters_to_remove = array( 'woocommerce_checkout_before_customer_details', 'woocommerce_checkout_after_customer_details', 'woocommerce_checkout_after_order_review', ); self::remove_filters( $filters_to_remove, 'Closure' ); } /* * The Neve theme. */ if ( strpos( $theme, 'neve' ) !== false ) { $filters_to_remove = array( 'woocommerce_checkout_before_customer_details', 'woocommerce_checkout_after_customer_details', 'woocommerce_checkout_before_order_review_heading', 'woocommerce_checkout_after_order_review', ); self::remove_filters( $filters_to_remove, 'Closure' ); } /* * Blocksy theme. */ if ( strpos( $theme, 'blocksy' ) !== false ) { do_action( 'cfw_checkout_main_container_start' ); } /* * Botiga theme, when the Review and Payments sections are shown together. */ if ( strpos( $theme, 'botiga' ) !== false ) { remove_action( 'woocommerce_checkout_before_order_review_heading', 'botiga_wrap_order_review_before', 5 ); remove_action( 'woocommerce_checkout_after_order_review', 'botiga_wrap_order_review_after', 15 ); add_filter( 'theme_mod_shop_checkout_layout', 'WMSC_Compatibilities::theme_mod_shop_checkout_layout', 20 ); } } /** * Remove filters calls, which were defined as closures or binded to a class. * * @param array $filters The hook names that are to be removed. * @param string $class The class name of the filter callback function. */ public static function remove_filters( $filters, $class = 'Closure' ) { global $wp_filter; if ( ! is_array( $wp_filter ) || count( $wp_filter ) === 0 ) { return; } foreach ( $filters as $_filter ) { if ( ! isset( $wp_filter[ $_filter ] ) ) { continue; } foreach ( $wp_filter[ $_filter ]->callbacks as $_p_key => $_priority ) { foreach ( $wp_filter[ $_filter ]->callbacks[ $_p_key ] as $_key => $_function ) { if ( ! isset( $_function['function'] ) ) { continue; } if ( is_array( $_function['function'] ) ) { if ( ! $_function['function'][0] instanceof $class ) { continue; } } else { if ( ! $_function['function'] instanceof $class ) { continue; } } unset( $wp_filter[ $_filter ]->callbacks[ $_p_key ][ $_key ] ); } } } } /** * The Login section is misplaced in the Neve theme. * * @param string $js JavaScript string. * @return string. */ public static function neve_remove_js( $js ) { $js = str_replace( '$( $( ".woocommerce-checkout div.woocommerce-info, .checkout_coupon, .woocommerce-form-login" ).detach() ).appendTo( "#neve-checkout-coupon" );', '', $js ); return $js; } /** * Woodmart buttons. * * @param string $btn The buttons' class. * @return string. */ public static function woodmart_buttons( $btn ) { return $btn . ' btn-color-primary'; } /** * TwentyTwentyTwo and TwentyTwentyThree buttons. * * @param string $btn The buttons' class. * @return string. */ public static function twentytwenty_buttons( $btn ) { return $btn . ' wp-element-button'; } /** * Astra Pro Addon plugin's checkout layout type. */ public static function astra_get_option_checkout_layout_type( $value, $option, $default ) { return 'default'; } /** * Add the content functions to the Payment and Order Review steps. */ public static function adjust_hooks() { if ( class_exists( 'WooCommerce_Germanized' ) ) { /* * Germanized for WooCommerce plugin. */ add_action( 'wmsc_step_content_review', 'wmsc_step_content_review_germanized', 10 ); add_action( 'wmsc_step_content_payment', 'wmsc_step_content_payment_germanized', 10 ); add_action( 'wpmc-woocommerce_order_review', 'woocommerce_gzd_template_render_checkout_checkboxes', 10 ); add_filter( 'wc_gzd_checkout_params', 'WMSC_Compatibilities::wc_gzd_checkout_params' ); add_filter( 'wp_loaded', 'WMSC_Compatibilities::woocommerce_review_order_after_payment' ); } elseif ( class_exists( 'Woocommerce_German_Market' ) ) { /* * WooCommerce German Market plugin. */ add_action( 'wmsc_step_content_review', 'wmsc_step_content_review_german_market', 10 ); add_action( 'wmsc_step_content_payment', 'wmsc_step_content_payment_german_market', 10 ); } else { /* * default. */ add_action( 'wmsc_step_content_review', 'wmsc_step_content_review', 10 ); add_action( 'wmsc_step_content_payment', 'wmsc_step_content_payment', 10 ); } } /** * Override parameters for the Germanized for WooCommerce plugin. * * @param array $params The parameters to be overriden. */ public static function wc_gzd_checkout_params( $params ) { $params['adjust_heading'] = false; return $params; } /** * Remove Terms and Conditions checkboxes from the Payment step for the Germanized for WooCommerce plugin. */ public static function woocommerce_review_order_after_payment() { remove_action( 'woocommerce_review_order_after_payment', 'woocommerce_gzd_template_render_checkout_checkboxes', 10 ); } /** * Scroll to top on Flatsome theme with sticky header. * * @param array $vars Options array. */ public static function flatsome_scroll_top( $vars ) { $vars['scroll_top'] = 120; return $vars; } /** * Choose "Version 1" option for the checkout version in Porto theme. * * @param string $version Version. */ public static function porto_checkout_version( $version ) { return 'v1'; } /** * Use the default WooCommerce template, if necessary. * * @param string $template Template file name. * @param string $template_name Template name. * @param string $template_path Template path. * * @return string */ public static function woocommerce_locate_template( $template, $template_name, $template_path ) { if ( ! is_checkout() ) { return $template; } $theme = strtolower( get_template() ); $wc_templates = plugin_dir_path( WC_PLUGIN_FILE ) . 'templates/'; $themes = array( 'puca' => array( 'myaccount/form-login.php', ), 'motors' => array( 'checkout/review-order.php', 'checkout/payment.php', ), ); $this_theme_files = apply_filters( 'wmsc_woocommerce_default_templates', array() ); /** * Example of using the "wmsc_woocommerce_default_templates" filter: * * Add_filter( 'wmsc_woocommerce_default_templates', function( $files ) { * return array('checkout/review-order.php', 'checkout/payment.php', 'myaccount/form-login.php'); * } ); */ if ( count( $this_theme_files ) > 0 ) { $themes[ $theme ] = $this_theme_files; } foreach ( $themes as $_theme => $_files ) { if ( strpos( $theme, $_theme ) !== false && in_array( $template_name, $_files, true ) ) { return $wc_templates . $template_name; } } return $template; } /** * The Germanized for WooCommerce plugin loads the WooCommerce form-checkout.php template, * if the Fallback Mode option is enabled on the "WP Admin -> WooCommerce -> Settings -> Germanized -> Button Solution" page. * * This function will load the form-checkout.php template from the multi-step checkout plugin instead of from the WooCommerce plugin. * * @param string $template Template file name. * @param string $template_name Template name. * @param string $template_path Template path. * * @return string */ public static function woocommerce_germanized_filter_template( $template, $template_name, $template_path ) { if ( ! class_exists( 'WooCommerce_Germanized' ) || get_option( 'woocommerce_gzd_display_checkout_fallback' ) !== 'yes' ) { return $template; } if ( strstr( $template_name, 'form-checkout.php' ) ) { $template = plugin_dir_path( WMSC_PLUGIN_FILE ) . 'includes/form-checkout.php'; } return $template; } /** * Override the Elementor Pro Checkout widget in order to remove the additional
Minimum Age fields in a separate step', 'wp-multi-step-checkout-pro' ),
'input_form' => 'checkbox',
'value' => false,
'section' => 'general',
),
);
$index = array_search( 'label2', array_keys( $settings ), true );
$settings = array_slice( $settings, 0, $index, true ) + $min_age + array_slice( $settings, $index, null, true );
return $settings;
}
/**
* Add option for the separate step for the minimum age fields.
*
* @param array $settings Settings array.
* @param string $current_section Current section.
*
* @return array
*/
public static function wpmc_minimum_age_settings( $settings, $current_section ) {
$end = array_pop( $settings );
$plugin_settings = admin_url( 'admin.php?page=wmsc-settings' );
$settings[] = array(
'id' => 'min_age_woo_wpmc_info',
'type' => 'info',
'text' => 'The age verification fields can be placed in a separate step from within the Multi-Step Checkout plugin options.',
);
$settings[] = $end;
return $settings;
}
/**
* Create a separate step for the minimum age fields.
*
* @param array $steps Steps array.
*
* @return array
*/
public static function wpmc_add_minimum_age_step( $steps ) {
$title = get_option( 'min_age_woo_checkout_title', _x( 'Verify your age', 'checkout section default', 'minimum-age-woocommerce' ) );
$steps['minimum_age'] = array(
'title' => $title,
'position' => 5,
'class' => 'wpmc-step-minimum-age',
'sections' => array( 'minimum_age' ),
);
return $steps;
}
/**
* Create the content for the minimum age fields.
*/
public static function wmsc_step_content_minimum_age() {
do_action( 'wpmc_minimum_age_woo_checkout_hook' );
}
/**
* Place the minimum age fields as content in the newly created step.
*
* @param string $action Action hook.
*
* @return string
*/
public static function mininum_age_woo_checkout_hook_filter( $action ) {
return 'wpmc_minimum_age_woo_checkout_hook';
}
/**
* Add a note on the Delivery & Pickup Date Time for WooCommerce plugin's settings page.
*
* @param array $settings Settings array.
*
* @return array
*/
public static function woo_delivery_admin_settings( $settings ) {
if ( ! defined( 'CODEROCKZ_WOO_DELIVERY' ) ) {
return $settings;
}
$woo_delivery = array(
'woo_delivery' => array(
'label' => __( 'Show the Delivery & Pickup Date Time fields in a separate step', 'wp-multi-step-checkout-pro' ),
'input_form' => 'checkbox',
'value' => false,
'section' => 'general',
),
);
$index = array_search( 'label2', array_keys( $settings ), true );
$settings = array_slice( $settings, 0, $index, true ) + $woo_delivery + array_slice( $settings, $index, null, true );
return $settings;
}
/**
* Separate step for the Delivery & Pickup Date Time for WooCommerce plugin by CodeRockz.
*
*/
public static function woo_delivery_plugin() {
if ( ! defined( 'CODEROCKZ_WOO_DELIVERY' ) ) {
return;
}
$options = get_option( 'wmsc_options', array() );
if ( ! isset( $options['woo_delivery'] ) || ! $options['woo_delivery'] ) {
return;
}
add_filter( 'wpmc_modify_steps', 'WMSC_Compatibilities::wpmc_add_woo_delivery_step' );
add_action( 'wmsc_step_content_woo_delivery', 'WMSC_Compatibilities::wmsc_step_content_woo_delivery' );
$woo_delivery_hooks = [
'woocommerce_checkout_billing',
'woocommerce_after_checkout_billing_form',
'woocommerce_checkout_shipping',
'woocommerce_after_checkout_shipping_form',
'woocommerce_before_order_notes',
'woocommerce_after_order_notes',
'woocommerce_review_order_before_payment',
'woocommerce_checkout_before_order_review_heading',
];
self::remove_filters( $woo_delivery_hooks, 'Coderockz_Woo_Delivery_Public' );
}
/**
* Create a separate step for the Woo Delivery fields.
*
* @param array $steps Steps array.
*
* @return array
*/
public static function wpmc_add_woo_delivery_step( $steps ) {
// Title.
$other_settings = get_option('coderockz_woo_delivery_other_settings');
$title = __( 'Delivery', 'woo-delivery' );
if ( isset($other_settings['delivery_heading_checkout']) && !empty($other_settings['delivery_heading_checkout']) ) {
$title = __(stripslashes($other_settings['delivery_heading_checkout']), 'woo-delivery');
}
// Position.
$position_translate = [
'before_billing' => 5,
'after_billing' => 15,
'before_shipping' => 15,
'before_payment' => 35,
];
$position = 25;
if ( isset($other_settings['field_position']) && isset( $position_translate[$other_settings['field_position']] ) ) {
$position = $position_translate[$other_settings['field_position']];
}
// Step definition.
$steps['woo_delivery'] = array(
'title' => $title,
'position' => $position,
'class' => 'wpmc-step-woo-delivery',
'sections' => array( 'woo_delivery' ),
);
return $steps;
}
/**
* Create the content for the Woo Delivery fields.
*/
public static function wmsc_step_content_woo_delivery() {
$version = defined( 'CODEROCKZ_WOO_DELIVERY_VERSION' ) ? CODEROCKZ_WOO_DELIVERY_VERSION : '1.0.0';
$plugin_public = new Coderockz_Woo_Delivery_Public( 'coderockz-woo-delivery', $version );
$plugin_public->coderockz_woo_delivery_add_custom_field();
}
}
WMSC_Compatibilities::init();