PluginProbe
Multi-Step Checkout for WooCommerce / 2.8
Multi-Step Checkout for WooCommerce v2.8
2.35.1 1.6 1.7 1.8 1.9 2.0 2.1 2.10 2.11 2.12 2.13 2.14 2.15 2.17 2.18 2.19 2.2 2.20 2.21 2.21.1 2.22 2.23 2.24 2.24.1 2.25 All 64 releases
wp-multi-step-checkout / wp-multi-step-checkout.php

wp-multi-step-checkout.php in Multi-Step Checkout for WooCommerce 2.8, at wp-multi-step-checkout.php

232 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: WooCommerce Multi-Step Checkout
4 * Plugin URI: https://wordpress.org/plugins/wp-multi-step-checkout/
5 * Description: Nice multi-step checkout for your WooCommerce store
6 * Version: 2.8
7 * Author: SilkyPress
8 * Author URI: https://www.silkypress.com
9 * License: GPL2
10 *
11 * Text Domain: wp-multi-step-checkout
12 * Domain Path: /languages/
13 *
14 * WC requires at least: 2.3.0
15 * WC tested up to: 3.9
16 * Requires PHP: 5.2.4
17 *
18 */
19
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit; // Exit if accessed directly
22 }
23
24 if ( ! class_exists( 'WPMultiStepCheckout' ) ) :
25 /**
26 * Main WPMultiStepCheckout Class
27 *
28 * @class WPMultiStepCheckout
29 */
30 final class WPMultiStepCheckout {
31 public $version = '2.8';
32 public $options = array();
33
34 protected static $_instance = null;
35
36
37 /**
38 * Main WPMultiStepCheckout Instance
39 *
40 * Ensures only one instance of WPMultiStepCheckout is loaded or can be loaded
41 *
42 * @static
43 * @return WPMultiStepCheckout - Main instance
44 */
45 public static function instance() {
46 if ( is_null( self::$_instance ) ) {
47 self::$_instance = new self();
48 }
49 return self::$_instance;
50 }
51
52 /**
53 * Cloning is forbidden.
54 */
55 public function __clone() {
56 _doing_it_wrong( __FUNCTION__, __( 'An error has occurred. Please reload the page and try again.' ), '1.0' );
57 }
58
59 /**
60 * Unserializing instances of this class is forbidden.
61 */
62 public function __wakeup() {
63 _doing_it_wrong( __FUNCTION__, __( 'An error has occurred. Please reload the page and try again.' ), '1.0' );
64 }
65
66 /**
67 * WPMultiStepCheckout Constructor
68 */
69 public function __construct() {
70
71 define('WMSC_PLUGIN_FILE', __FILE__);
72 define('WMSC_PLUGIN_URL', plugins_url('/', __FILE__));
73 define('WMSC_PLUGIN_PATH', plugin_dir_url('/', __FILE__));
74 define('WMSC_VERSION', $this->version );
75
76 if ( ! class_exists('woocommerce') ) {
77 add_action( 'admin_notices', array($this, 'install_woocommerce_admin_notice' ) );
78 return false;
79 }
80
81 if ( is_admin() ) {
82 include_once 'includes/admin-side.php';
83 }
84
85 $this->update_14_version();
86
87 add_filter( 'woocommerce_locate_template', array( $this, 'woocommerce_locate_template' ), 10, 3 );
88
89 $this->adjust_hooks();
90
91 add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
92
93 add_action( 'init', array($this, 'load_plugin_textdomain' ) );
94
95 include_once 'includes/class-wmsc-compatibilities.php';
96 }
97
98
99 /**
100 * Modify the default WooCommerce hooks
101 */
102 public function adjust_hooks() {
103 // Remove login messages
104 remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form', 10 );
105 remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
106
107 // Split the `Order` and the `Payment` tabs
108 remove_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
109 remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
110 add_action( 'wpmc-woocommerce_order_review', 'woocommerce_order_review', 20 );
111 add_action( 'wpmc-woocommerce_checkout_payment', 'woocommerce_checkout_payment', 10 );
112
113 // Split the `woocommerce_before_checkout_form`
114 remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form', 10 );
115 remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
116 add_action( 'wpmc-woocommerce_checkout_login_form', 'woocommerce_checkout_login_form', 10 );
117 add_action( 'wpmc-woocommerce_checkout_coupon_form', 'woocommerce_checkout_coupon_form', 10 );
118
119 // Add the content functions to the steps
120 add_action( 'wmsc_step_content_login', 'wmsc_step_content_login', 10);
121 add_action( 'wmsc_step_content_shipping', 'wmsc_step_content_shipping', 10);
122 add_action( 'wmsc_step_content_billing', 'wmsc_step_content_billing', 10);
123 }
124
125 /**
126 * Load the form-checkout.php template from this plugin
127 */
128 public function woocommerce_locate_template( $template, $template_name, $template_path ){
129 if( 'checkout/form-checkout.php' != $template_name )
130 return $template;
131 $template = plugin_dir_path( __FILE__ ) . 'includes/form-checkout.php';
132 return $template;
133 }
134
135 /**
136 * Enqueue the JS and CSS assets
137 */
138 public function wp_enqueue_scripts() {
139
140 if ( ! is_checkout() ) {
141 return;
142 }
143
144 $options = get_option( 'wmsc_options' );
145 $keyboard_nav = ( isset( $options['keyboard_nav'] ) && $options['keyboard_nav'] ) ? true : false;
146 $color = ( isset( $options['main_color'] ) ) ? wp_strip_all_tags( $options['main_color'] ) : '#1e85be';
147 $url = plugins_url( '/', __FILE__ ) . 'assets/';
148 $prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
149
150 // Load scripts
151 wp_register_script( 'wpmc', $url . 'js/script' . $prefix . '.js', array( 'jquery' ), $this->version, false );
152 wp_localize_script( 'wpmc', 'WPMC', apply_filters( 'wmsc_js_variables', array( 'keyboard_nav' => $keyboard_nav ) ) );
153 wp_register_style ( 'wpmc', $url . 'css/style-progress' . $prefix . '.css', array(), $this->version );
154
155 wp_enqueue_script ( 'wpmc' );
156 wp_enqueue_style ( 'wpmc' );
157
158 // Load the inline styles
159 $style = '.wpmc-tabs-wrapper .wpmc-tab-item.current::before { border-bottom-color:' . $color . '; }';
160 $style .= '.wpmc-tabs-wrapper .wpmc-tab-item.current .wpmc-tab-number { border-color: ' . $color . '; }';
161 if ( is_rtl() ) {
162 $style .= '.wpmc-tabs-list .wpmc-tab-item { float: right; }';
163 }
164 wp_add_inline_style( 'wpmc', $style );
165 }
166
167 /**
168 * Admin notice that WooCommerce is not activated
169 */
170 public function install_woocommerce_admin_notice() {
171 ?>
172 <div class="error">
173 <p><?php _e( 'The WP Multi-Step Checkout plugin is enabled, but it requires WooCommerce in order to work.', 'Alert Message: WooCommerce require', 'wp-multi-step-checkout' ); ?></p>
174 </div>
175 <?php
176 }
177
178
179 /**
180 * Load the textdomain
181 */
182 public function load_plugin_textdomain() {
183 load_plugin_textdomain( 'wp-multi-step-checkout', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
184 }
185
186
187 /**
188 * Update options array for the 1.4 version
189 */
190 function update_14_version() {
191 if ( ! $old_options = get_option('wpmc-settings') ) return;
192
193 require_once 'includes/settings-array.php';
194 $defaults = get_wmsc_settings('wp-multi-step-checkout');
195
196
197 $new_options = array();
198 foreach($defaults as $_key => $_value ) {
199 if ( isset($old_options[$_key]) ) {
200 $new_options[$_key] = $old_options[$_key][2];
201 } else {
202 $new_options[$_key] = $_value['value'];
203 }
204 }
205
206 update_option('wmsc_options', $new_options);
207 delete_option('wpmc-settings');
208 }
209
210 }
211
212 endif;
213
214 /**
215 * Returns the main instance of WPMultiStepCheckout
216 *
217 * @return WPMultiStepCheckout
218 */
219 function WPMultiStepCheckout() {
220 return WPMultiStepCheckout::instance();
221 }
222
223 WPMultiStepCheckout();
224
225 function wpmc_plugin_settings_link($links) {
226 $action_links = array(
227 '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>',
228 );
229 return array_merge( $action_links, $links );
230 }
231 add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'wpmc_plugin_settings_link');
232