| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Multi-Step Checkout for WooCommerce |
| 4 |
* Requires Plugins: woocommerce |
| 5 |
* Plugin URI: https://wordpress.org/plugins/wp-multi-step-checkout/ |
| 6 |
* Description: Split the different sections of the default WooCommerce checkout page into multiple steps |
| 7 |
* Version: 2.35.1 |
| 8 |
* Author: SilkyPress |
| 9 |
* Author URI: https://www.silkypress.com |
| 10 |
* |
| 11 |
* Text Domain: wp-multi-step-checkout |
| 12 |
* Domain Path: /languages/ |
| 13 |
* |
| 14 |
* WC requires at least: 3.0.0 |
| 15 |
* WC tested up to: 11.1 |
| 16 |
* Requires PHP: 5.2.4 |
| 17 |
* |
| 18 |
* @package WPMultiStepCheckout |
| 19 |
*/ |
| 20 |
|
| 21 |
if ( ! defined( 'ABSPATH' ) ) { |
| 22 |
exit; // Exit if accessed directly. |
| 23 |
} |
| 24 |
|
| 25 |
if ( ! class_exists( 'WPMultiStepCheckout' ) ) : |
| 26 |
/** |
| 27 |
* @class WPMultiStepCheckout |
| 28 |
*/ |
| 29 |
class WPMultiStepCheckout { |
| 30 |
|
| 31 |
/** |
| 32 |
* Plugin's version. |
| 33 |
* |
| 34 |
* @var string |
| 35 |
*/ |
| 36 |
public static $version = '2.35.1'; |
| 37 |
|
| 38 |
/** |
| 39 |
* Plugin's options. |
| 40 |
* |
| 41 |
* @var array |
| 42 |
*/ |
| 43 |
public static $options = array(); |
| 44 |
|
| 45 |
|
| 46 |
public function __construct() {} |
| 47 |
|
| 48 |
/** |
| 49 |
* WPMultiStepCheckout plugin init. |
| 50 |
*/ |
| 51 |
public static function init() { |
| 52 |
|
| 53 |
define( 'WMSC_PLUGIN_FILE', __FILE__ ); |
| 54 |
define( 'WMSC_PLUGIN_URL', plugins_url( '/', __FILE__ ) ); |
| 55 |
define( 'WMSC_PLUGIN_PATH', plugin_dir_url( '/', __FILE__ ) ); |
| 56 |
define( 'WMSC_VERSION', self::$version ); |
| 57 |
|
| 58 |
if ( class_exists( 'WPMultiStepCheckoutPro' ) ) { |
| 59 |
return false; |
| 60 |
} |
| 61 |
|
| 62 |
if ( ! class_exists( 'woocommerce' ) ) { |
| 63 |
add_action( 'admin_notices', array( __CLASS__, 'install_woocommerce_admin_notice' ) ); |
| 64 |
return false; |
| 65 |
} |
| 66 |
|
| 67 |
if ( is_admin() ) { |
| 68 |
include_once 'includes/admin-side.php'; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
// Disable on mobile devices, if necessary. |
| 73 |
self::$options = get_option( 'wmsc_options', array() ); |
| 74 |
if ( isset( self::$options['disable_mobile'] ) && self::$options['disable_mobile'] && wp_is_mobile() ) { |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
self::update_14_version(); |
| 80 |
|
| 81 |
add_filter( 'woocommerce_locate_template', array( __CLASS__, 'woocommerce_locate_template' ), 30, 3 ); |
| 82 |
|
| 83 |
self::adjust_hooks(); |
| 84 |
|
| 85 |
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'wp_enqueue_scripts' ) ); |
| 86 |
|
| 87 |
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( __CLASS__, 'settings_link' ) ); |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
/** |
| 93 |
* Modify the default WooCommerce hooks |
| 94 |
*/ |
| 95 |
public static function adjust_hooks() { |
| 96 |
// Remove login messages. |
| 97 |
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form', 10 ); |
| 98 |
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 ); |
| 99 |
|
| 100 |
// Split the `Order` and the `Payment` tabs. |
| 101 |
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 ); |
| 102 |
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 ); |
| 103 |
add_action( 'wpmc-woocommerce_order_review', 'woocommerce_order_review', 20 ); |
| 104 |
add_action( 'wpmc-woocommerce_checkout_payment', 'woocommerce_checkout_payment', 10 ); |
| 105 |
|
| 106 |
// Split the `woocommerce_before_checkout_form`. |
| 107 |
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form', 10 ); |
| 108 |
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 ); |
| 109 |
add_action( 'wpmc-woocommerce_checkout_login_form', 'woocommerce_checkout_login_form', 10 ); |
| 110 |
add_action( 'wpmc-woocommerce_checkout_coupon_form', 'woocommerce_checkout_coupon_form', 10 ); |
| 111 |
|
| 112 |
// Add the content functions to the steps. |
| 113 |
add_action( 'wmsc_step_content_login', 'wmsc_step_content_login', 10 ); |
| 114 |
add_action( 'wmsc_step_content_shipping', 'wmsc_step_content_shipping', 10 ); |
| 115 |
add_action( 'wmsc_step_content_billing', 'wmsc_step_content_billing', 10 ); |
| 116 |
|
| 117 |
add_filter( 'wmsc_delete_step_by_category', array( __CLASS__, 'hide_shipping_step_virtual' ) ); |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Load the form-checkout.php template from this plugin. |
| 122 |
* |
| 123 |
* @param string $template Template name. |
| 124 |
* @param string $template_name Template name. |
| 125 |
* @param string $template_path Template path. (default: ''). |
| 126 |
* @return string |
| 127 |
*/ |
| 128 |
public static function woocommerce_locate_template( $template, $template_name, $template_path ) { |
| 129 |
if ( 'checkout/form-checkout.php' !== $template_name ) { |
| 130 |
return $template; |
| 131 |
} |
| 132 |
$template = plugin_dir_path( __FILE__ ) . 'includes/form-checkout.php'; |
| 133 |
return $template; |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Enqueue the JS and CSS assets |
| 138 |
*/ |
| 139 |
public static function wp_enqueue_scripts() { |
| 140 |
|
| 141 |
if ( ! is_checkout() ) { |
| 142 |
return; |
| 143 |
} |
| 144 |
|
| 145 |
$keyboard_nav = ( isset( self::$options['keyboard_nav'] ) && self::$options['keyboard_nav'] ) ? true : false; |
| 146 |
$color = ( isset( self::$options['main_color'] ) ) ? wp_strip_all_tags( self::$options['main_color'] ) : '#1e85be'; |
| 147 |
$url = plugins_url( '/', __FILE__ ) . 'assets/'; |
| 148 |
$prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
| 149 |
|
| 150 |
// JS variables. |
| 151 |
$vars = array( 'keyboard_nav' => $keyboard_nav ); |
| 152 |
$vars_filters = array( 'hide_last_prev', 'hide_last_back_to_cart', 'skip_login_above_form', 'skip_login_next_to_login_button' ); |
| 153 |
foreach ( $vars_filters as $_filter ) { |
| 154 |
if ( apply_filters( 'wpmc_' . $_filter, false ) ) { |
| 155 |
$vars[ $_filter ] = true; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
// Load scripts. |
| 160 |
wp_register_script( 'wpmc', $url . 'js/script' . $prefix . '.js', array( 'jquery' ), self::$version, true ); |
| 161 |
wp_localize_script( 'wpmc', 'WPMC', apply_filters( 'wmsc_js_variables', $vars ) ); |
| 162 |
wp_register_style( 'wpmc', $url . 'css/style-progress' . $prefix . '.css', array(), self::$version ); |
| 163 |
|
| 164 |
wp_enqueue_script( 'wpmc' ); |
| 165 |
wp_enqueue_style( 'wpmc' ); |
| 166 |
|
| 167 |
// Load the inline styles. |
| 168 |
$style = '.wpmc-tabs-wrapper .wpmc-tab-item.current::before { border-bottom-color:' . $color . '; }'; |
| 169 |
$style .= '.wpmc-tabs-wrapper .wpmc-tab-item.current .wpmc-tab-number { border-color: ' . $color . '; }'; |
| 170 |
if ( is_rtl() ) { |
| 171 |
$style .= '.wpmc-tabs-list .wpmc-tab-item { float: right; }'; |
| 172 |
} |
| 173 |
wp_add_inline_style( 'wpmc', $style ); |
| 174 |
} |
| 175 |
|
| 176 |
/** |
| 177 |
* Admin notice that WooCommerce is not activated |
| 178 |
*/ |
| 179 |
public static function install_woocommerce_admin_notice() { |
| 180 |
?> |
| 181 |
<div class="error"> |
| 182 |
<p><?php _x( 'The <b>Multi-Step Checkout for WooCommerce</b> plugin is enabled, but it requires WooCommerce in order to work.', 'Alert Message: WooCommerce require', 'wp-multi-step-checkout' ); ?></p> |
| 183 |
</div> |
| 184 |
<?php |
| 185 |
} |
| 186 |
|
| 187 |
/** |
| 188 |
* Add Settings link on the Plugins page. |
| 189 |
* |
| 190 |
* @param array $links Currently available links. |
| 191 |
*/ |
| 192 |
public static function settings_link( $links ) { |
| 193 |
$action_links = array( |
| 194 |
'settings' => '<a href="' . admin_url( 'admin.php?page=wmsc-settings' ) . '" aria-label="' . esc_attr__( 'View plugin\'s settings', 'wp-multi-step-checkout' ) . '">' . esc_html__( 'Settings', 'wp-multi-step-checkout' ) . '</a>', |
| 195 |
); |
| 196 |
return array_merge( $action_links, $links ); |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
/** |
| 201 |
* Update options array for the 1.4 version |
| 202 |
*/ |
| 203 |
public static function update_14_version() { |
| 204 |
if ( ! $old_options = get_option( 'wpmc-settings' ) ) { |
| 205 |
return; |
| 206 |
} |
| 207 |
|
| 208 |
require_once 'includes/settings-array.php'; |
| 209 |
$defaults = get_wmsc_settings(); |
| 210 |
|
| 211 |
$new_options = array(); |
| 212 |
foreach ( $defaults as $_key => $_value ) { |
| 213 |
if ( isset( $old_options[ $_key ] ) ) { |
| 214 |
$new_options[ $_key ] = $old_options[ $_key ][2]; |
| 215 |
} else { |
| 216 |
$new_options[ $_key ] = $_value['value']; |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
update_option( 'wmsc_options', $new_options ); |
| 221 |
delete_option( 'wpmc-settings' ); |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
/* |
| 226 |
* Hide the "Shipping" step if there are only virtual products in the cart. |
| 227 |
*/ |
| 228 |
public static function hide_shipping_step_virtual( $settings ) { |
| 229 |
|
| 230 |
if ( isset( self::$options['hide_shipping_step_virtual'] ) && self::$options['hide_shipping_step_virtual'] ) { |
| 231 |
$settings['virtual_products'] = true; |
| 232 |
} |
| 233 |
|
| 234 |
return $settings; |
| 235 |
} |
| 236 |
|
| 237 |
} |
| 238 |
|
| 239 |
add_action( 'init', array( 'WPMultiStepCheckout', 'init' ) ); |
| 240 |
|
| 241 |
|
| 242 |
include_once 'includes/class-wmsc-compatibilities.php'; |
| 243 |
|
| 244 |
endif; |
| 245 |
|