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

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