PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.10.0
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.10.0
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 / product-audio / class-product-audio.php

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

158 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Product Audio
5 *
6 * @package Merchant
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 /**
14 * Product audio class.
15 *
16 */
17 class Merchant_Product_Audio extends Merchant_Add_Module {
18
19 /**
20 * Module ID.
21 *
22 */
23 const MODULE_ID = 'product-audio';
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 = 'improve-experience';
48
49 // Mount preview url.
50 $preview_url = site_url( '/' );
51
52 if ( function_exists( 'wc_get_products' ) ) {
53 $products = wc_get_products( array( 'limit' => 1 ) );
54
55 if ( ! empty( $products ) && ! empty( $products[0] ) ) {
56 $preview_url = get_permalink( $products[0]->get_id() );
57 }
58 }
59
60 // Module data.
61 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
62 $this->module_data[ 'preview_url' ] = $preview_url;
63
64 // Module options path.
65 $this->module_options_path = MERCHANT_DIR . 'inc/modules/product-audio/admin/options.php';
66
67 // Is module preview page.
68 if ( is_admin() && parent::is_module_settings_page() ) {
69 self::$is_module_preview = true;
70
71 // Enqueue admin styles.
72 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
73
74 // Render module essencial instructions before the module page body content.
75 add_action( 'merchant_admin_after_module_page_page_header', array( $this, 'admin_module_essencial_instructions' ) );
76
77 // Admin preview box.
78 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
79 }
80 }
81
82 /**
83 * Admin enqueue CSS.
84 *
85 * @return void
86 */
87 public function admin_enqueue_css() {
88 if ( parent::is_module_settings_page()) {
89 wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/product-audio.min.css', array(), MERCHANT_VERSION );
90 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
91 }
92 }
93
94 /**
95 * Render module essencial instructions.
96 *
97 * @return void
98 */
99 public function admin_module_essencial_instructions() { ?>
100 <div class="merchant-module-page-settings">
101 <div class="merchant-module-page-setting-box merchant-module-page-setting-box-style-2">
102 <div class="merchant-module-page-setting-fields">
103 <div class="merchant-module-page-setting-field merchant-module-page-setting-field-content">
104 <div class="merchant-module-page-setting-field-inner">
105 <div class="merchant-tag-pre-orders">
106 <i class="dashicons dashicons-info"></i>
107 <p><?php echo esc_html__( 'Once this module is enabled new options to upload audio files will appear under the admin product edit page. This means you have to edit and upload the audio file for each product in your store.', 'merchant' ); ?> <?php printf( '<a href="%s" target="_blank">%s</a>', esc_url( admin_url( 'edit.php?post_type=product' ) ), esc_html__( 'View All Products', 'merchant' ) ); ?></p>
108 </div>
109 </div>
110 </div>
111 </div>
112 </div>
113 </div>
114
115 <?php
116 }
117
118 /**
119 * Render admin preview
120 *
121 * @param Merchant_Admin_Preview $preview
122 * @param string $module
123 *
124 * @return Merchant_Admin_Preview
125 */
126 public function render_admin_preview( $preview, $module ) {
127 if ( self::MODULE_ID === $module ) {
128 ob_start();
129 self::admin_preview_content();
130 $content = ob_get_clean();
131
132 // HTML.
133 $preview->set_html( $content );
134 }
135
136 return $preview;
137 }
138
139 /**
140 * Admin preview content.
141 *
142 * @return void
143 */
144 public function admin_preview_content() { ?>
145
146 <div class="mrc-product-audio-preview">
147 <img alt="product audio" src="<?php echo esc_url( MERCHANT_URI . 'inc/modules/product-audio/admin/images/preview-product-audio.png' ); ?>" />
148 </div>
149
150 <?php
151 }
152 }
153
154 // Initialize the module.
155 add_action( 'init', function() {
156 Merchant_Modules::create_module(new Merchant_Product_Audio());
157 } );
158