PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.3.2
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.3.2
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 2.3.2, at inc/modules/checkout/class-checkout.php

157 lines 4.4 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 * Initialize the module's option group definitions.
33 *
34 * @return array<int, array<string, mixed>> Array of option group arrays.
35 */
36 protected function init_option_groups() {
37 return require MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
38 }
39
40 /**
41 * Constructor.
42 *
43 */
44 public function __construct() {
45
46 // Module id.
47 $this->module_id = self::MODULE_ID;
48
49 // WooCommerce only.
50 $this->wc_only = true;
51
52 // Parent construct.
53 parent::__construct();
54
55 // Module section.
56 $this->module_section = 'convert-more';
57
58 // Module default settings.
59 $this->module_default_settings = array(
60 'layout' => 'layout-shopify',
61 'sticky_totals_box' => 0,
62 );
63
64 // Module data.
65 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
66
67 // AI prompt examples.
68 $this->ai_examples = array(
69 'blurb' => esc_html__( 'See what AI can do for your checkout, from switching between the Shopify-style, one-step, and multi-step layouts to keeping the order totals box sticky as shoppers scroll.', 'merchant' ),
70 'prompts' => array(
71 esc_html__( 'Explore the abilities WPVibe gives you access to, then switch my checkout to the one-step layout', 'merchant' ),
72 esc_html__( 'Check what abilities you have available through WPVibe, then change the checkout to the multi-step layout instead', 'merchant' ),
73 esc_html__( 'Look at your available WPVibe abilities, then switch to the Shopify-style layout and keep the order totals box sticky as shoppers scroll', 'merchant' ),
74 ),
75 );
76
77 // Module options path.
78 $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
79
80 // Is module preview page.
81 if ( is_admin() && parent::is_module_settings_page() ) {
82 self::$is_module_preview = true;
83
84 // Enqueue admin styles.
85 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
86
87 // Admin preview box.
88 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
89
90 }
91 }
92
93 /**
94 * Admin enqueue CSS.
95 *
96 * @return void
97 */
98 public function admin_enqueue_css() {
99 $page = ( ! empty( $_GET['page'] ) ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
100 $module = ( ! empty( $_GET['module'] ) ) ? sanitize_text_field( wp_unslash( $_GET['module'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
101
102 if ( 'merchant' === $page && self::MODULE_ID === $module ) {
103 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
104 }
105 }
106
107 /**
108 * Render admin preview
109 *
110 * @param Merchant_Admin_Preview $preview
111 * @param string $module
112 *
113 * @return Merchant_Admin_Preview
114 */
115 public function render_admin_preview( $preview, $module ) {
116 if ( self::MODULE_ID === $module ) {
117 ob_start();
118 $this->checkout_admin_preview_output();
119 $content = ob_get_clean();
120
121 // HTML.
122 $preview->set_html( $content );
123
124 // Toggle layout class identifier.
125 $preview->set_class( 'layout', '.mrc-checkout-preview', array( 'layout-shopify', 'layout-one-step', 'layout-multi-step' ) );
126
127 }
128
129 return $preview;
130 }
131
132 public function checkout_admin_preview_output() {
133 $settings = $this->get_module_settings();
134
135 ?>
136
137 <div class="mrc-checkout-preview <?php echo esc_attr( $settings[ 'layout' ] ); ?>">
138 <div class="mrc-checkout-preview-one-step">
139 <img src="<?php echo esc_url( MERCHANT_URI . 'inc/modules/checkout/admin/images/preview-layout-one-step.png' ); ?>" />
140 </div>
141 <div class="mrc-checkout-preview-shopify">
142 <img src="<?php echo esc_url( MERCHANT_URI . 'inc/modules/checkout/admin/images/preview-layout-shopify.png' ); ?>" />
143 </div>
144 <div class="mrc-checkout-preview-multi-step">
145 <img src="<?php echo esc_url( MERCHANT_URI . 'inc/modules/checkout/admin/images/preview-layout-multi-step.png' ); ?>" />
146 </div>
147 </div>
148
149 <?php
150 }
151 }
152
153 // Initialize the module.
154 add_action( 'init', function () {
155 Merchant_Modules::create_module( new Merchant_Checkout() );
156 } );
157