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 / address-autocomplete / class-address-autocomplete.php

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

147 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Add To Cart Text
5 *
6 * @package Merchant
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 /**
14 * Add To Cart Text Class.
15 *
16 */
17 class Merchant_Address_Autocomplete extends Merchant_Add_Module {
18
19 /**
20 * Module ID.
21 */
22 const MODULE_ID = 'address-autocomplete';
23
24 /**
25 * Is module preview.
26 *
27 */
28 public static $is_module_preview = false;
29
30 /**
31 * Initialize the module's option group definitions.
32 *
33 * @return array<int, array<string, mixed>> Array of option group arrays.
34 */
35 protected function init_option_groups() {
36 return require MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
37 }
38
39 /**
40 * Constructor.
41 *
42 */
43 public function __construct() {
44 // Module id.
45 $this->module_id = self::MODULE_ID;
46
47 // WooCommerce only.
48 $this->wc_only = true;
49
50 // Parent construct.
51 parent::__construct();
52
53 // Module data.
54 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
55
56 // Module section.
57 $this->module_section = $this->module_data['section'];
58
59 // AI prompt examples.
60 $this->ai_examples = array(
61 'blurb' => esc_html__( 'See what AI can do for your checkout address autocomplete, from switching it on to connecting your Google Places API key.', 'merchant' ),
62 'prompts' => array(
63 esc_html__( 'Explore the abilities WPVibe gives you access to, then turn on Google address autocomplete at checkout', 'merchant' ),
64 esc_html__( 'Check what abilities you have available through WPVibe, then add my Google Places API key so the address autocomplete starts suggesting addresses', 'merchant' ),
65 esc_html__( "Look at your available WPVibe abilities, then set the address autocomplete's optional API URL parameters to region=us and language=en", 'merchant' ),
66 ),
67 );
68
69 // Module options path.
70 $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
71
72 // Is module preview page.
73 if ( is_admin() && parent::is_module_settings_page() ) {
74 self::$is_module_preview = true;
75
76 // Enqueue admin styles.
77 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
78
79 // Admin preview box.
80 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
81 }
82 }
83
84 /**
85 * Admin enqueue CSS.
86 *
87 * @return void
88 */
89 public function admin_enqueue_css() {
90 if ( $this->is_module_settings_page() ) {
91 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
92 wp_enqueue_script(
93 'merchant-admin-' . self::MODULE_ID,
94 MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/admin/preview.min.js',
95 array( 'jquery' ),
96 MERCHANT_VERSION,
97 true
98 );
99 wp_localize_script(
100 'merchant-admin-' . self::MODULE_ID,
101 'merchant_admin_address_autocomplete',
102 array(
103 'field_placeholder' => esc_attr__( 'Start typing an address...', 'merchant' ),
104 )
105 );
106 }
107 }
108
109 /**
110 * Render admin preview
111 *
112 * @param Merchant_Admin_Preview $preview
113 * @param string $module
114 *
115 * @return Merchant_Admin_Preview
116 */
117 public function render_admin_preview( $preview, $module ) {
118 if ( $module === self::MODULE_ID ) {
119 // HTML.
120 $preview->set_html( array( $this, 'admin_preview_content' ), $this->get_module_settings() );
121 }
122
123 return $preview;
124 }
125
126 /**
127 * Admin preview content.
128 *
129 * @return void
130 */
131 public function admin_preview_content( $settings ) {
132 ?>
133 <div class="merchant-preview">
134 <p class="address">
135 <label for="merchant-address-autocomplete"><?php esc_html_e( 'Street address', 'merchant' ); ?></label>
136 <input type="text" id="merchant-address-autocomplete" class="merchant-address-autocomplete" placeholder="<?php esc_attr_e( 'Start typing an address...', 'merchant' ); ?>">
137 </p>
138 </div>
139 <?php
140 }
141 }
142
143 // Initialize the module.
144 add_action( 'init', function () {
145 Merchant_Modules::create_module( new Merchant_Address_Autocomplete() );
146 } );
147