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

128 lines 3.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 * Constructor.
32 *
33 */
34 public function __construct() {
35 // Module id.
36 $this->module_id = self::MODULE_ID;
37
38 // WooCommerce only.
39 $this->wc_only = true;
40
41 // Parent construct.
42 parent::__construct();
43
44 // Module data.
45 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
46
47 // Module section.
48 $this->module_section = $this->module_data['section'];
49
50 // Module options path.
51 $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
52
53 // Is module preview page.
54 if ( is_admin() && parent::is_module_settings_page() ) {
55 self::$is_module_preview = true;
56
57 // Enqueue admin styles.
58 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
59
60 // Admin preview box.
61 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
62 }
63 }
64
65 /**
66 * Admin enqueue CSS.
67 *
68 * @return void
69 */
70 public function admin_enqueue_css() {
71 if ( $this->is_module_settings_page() ) {
72 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
73 wp_enqueue_script(
74 'merchant-admin-' . self::MODULE_ID,
75 MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/admin/preview.min.js',
76 array( 'jquery' ),
77 MERCHANT_VERSION,
78 true
79 );
80 wp_localize_script(
81 'merchant-admin-' . self::MODULE_ID,
82 'merchant_admin_address_autocomplete',
83 array(
84 'field_placeholder' => esc_attr__( 'Start typing an address...', 'merchant' ),
85 )
86 );
87 }
88 }
89
90 /**
91 * Render admin preview
92 *
93 * @param Merchant_Admin_Preview $preview
94 * @param string $module
95 *
96 * @return Merchant_Admin_Preview
97 */
98 public function render_admin_preview( $preview, $module ) {
99 if ( $module === self::MODULE_ID ) {
100 // HTML.
101 $preview->set_html( array( $this, 'admin_preview_content' ), $this->get_module_settings() );
102 }
103
104 return $preview;
105 }
106
107 /**
108 * Admin preview content.
109 *
110 * @return void
111 */
112 public function admin_preview_content( $settings ) {
113 ?>
114 <div class="merchant-preview">
115 <p class="address">
116 <label for="merchant-address-autocomplete"><?php esc_html_e( 'Street address', 'merchant' ); ?></label>
117 <input type="text" id="merchant-address-autocomplete" class="merchant-address-autocomplete" placeholder="<?php esc_attr_e( 'Start typing an address...', 'merchant' ); ?>">
118 </p>
119 </div>
120 <?php
121 }
122 }
123
124 // Initialize the module.
125 add_action( 'init', function () {
126 Merchant_Modules::create_module( new Merchant_Address_Autocomplete() );
127 } );
128