PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.8.3
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.8.3
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / inc / modules / checkout / class-checkout.php

class-checkout.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 1.8.3, at inc/modules/checkout/class-checkout.php

146 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Checkout
5 *
6 * @package Merchant
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 /**
14 * Checkout class.
15 *
16 */
17 class Merchant_Checkout extends Merchant_Add_Module {
18
19 /**
20 * Module ID.
21 *
22 */
23 const MODULE_ID = 'checkout';
24
25 /**
26 * Is module preview.
27 *
28 */
29 public static $is_module_preview = false;
30
31 /**
32 * Constructor.
33 *
34 */
35 public function __construct() {
36
37 // Module id.
38 $this->module_id = self::MODULE_ID;
39
40 // WooCommerce only.
41 $this->wc_only = true;
42
43 // Parent construct.
44 parent::__construct();
45
46 // Module section.
47 $this->module_section = 'convert-more';
48
49 // Module default settings.
50 $this->module_default_settings = array(
51 'layout' => 'layout-shopify',
52 'sticky_totals_box' => 0,
53 );
54
55 // Mount preview url.
56 $preview_url = site_url( '/' );
57
58 if ( function_exists( 'wc_get_page_id' ) ) {
59 $preview_url = get_permalink( wc_get_page_id( 'checkout' ) );
60 }
61
62 // Module data.
63 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
64 $this->module_data[ 'preview_url' ] = $preview_url;
65
66 // Module options path.
67 $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
68
69 // Is module preview page.
70 if ( is_admin() && parent::is_module_settings_page() ) {
71 self::$is_module_preview = true;
72
73 // Enqueue admin styles.
74 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
75
76 // Admin preview box.
77 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
78
79 }
80 }
81
82 /**
83 * Admin enqueue CSS.
84 *
85 * @return void
86 */
87 public function admin_enqueue_css() {
88 $page = ( ! empty( $_GET['page'] ) ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
89 $module = ( ! empty( $_GET['module'] ) ) ? sanitize_text_field( wp_unslash( $_GET['module'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
90
91 if ( 'merchant' === $page && self::MODULE_ID === $module ) {
92 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
93 }
94 }
95
96 /**
97 * Render admin preview
98 *
99 * @param Merchant_Admin_Preview $preview
100 * @param string $module
101 *
102 * @return Merchant_Admin_Preview
103 */
104 public function render_admin_preview( $preview, $module ) {
105 if ( self::MODULE_ID === $module ) {
106 ob_start();
107 $this->checkout_admin_preview_output();
108 $content = ob_get_clean();
109
110 // HTML.
111 $preview->set_html( $content );
112
113 // Toggle layout class identifier.
114 $preview->set_class( 'layout', '.mrc-checkout-preview', array( 'layout-shopify', 'layout-one-step', 'layout-multi-step' ) );
115
116 }
117
118 return $preview;
119 }
120
121 public function checkout_admin_preview_output() {
122 $settings = $this->get_module_settings();
123
124 ?>
125
126 <div class="mrc-checkout-preview <?php echo esc_attr( $settings[ 'layout' ] ); ?>">
127 <div class="mrc-checkout-preview-one-step">
128 <img src="<?php echo esc_url( MERCHANT_URI . 'inc/modules/checkout/admin/images/preview-layout-one-step.png' ); ?>" />
129 </div>
130 <div class="mrc-checkout-preview-shopify">
131 <img src="<?php echo esc_url( MERCHANT_URI . 'inc/modules/checkout/admin/images/preview-layout-shopify.png' ); ?>" />
132 </div>
133 <div class="mrc-checkout-preview-multi-step">
134 <img src="<?php echo esc_url( MERCHANT_URI . 'inc/modules/checkout/admin/images/preview-layout-multi-step.png' ); ?>" />
135 </div>
136 </div>
137
138 <?php
139 }
140 }
141
142 // Initialize the module.
143 add_action( 'init', function () {
144 Merchant_Modules::create_module( new Merchant_Checkout() );
145 } );
146