PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.10.5
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.10.5
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 / compatibility / class-merchant-divi-theme.php

class-merchant-divi-theme.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 1.10.5, at inc/compatibility/class-merchant-divi-theme.php

213 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly
4 }
5
6 /**
7 * Divi theme compatibility layer
8 */
9 if ( ! class_exists( 'Merchant_Divi_Theme' ) ) {
10 class Merchant_Divi_Theme {
11
12 /**
13 * Constructor.
14 */
15 public function __construct() {
16
17 if ( ( is_admin() && ! wp_doing_ajax() ) || ! merchant_is_divi_active() ) {
18 return;
19 }
20
21 if ( Merchant_Modules::is_module_active( Merchant_Quick_View::MODULE_ID ) ) {
22 add_filter( 'merchant_quick_view_description', array( $this, 'quick_view_description' ) );
23 }
24
25 if ( merchant_is_pro_active() ) {}
26
27 //add_filter( 'merchant_module_settings', array( $this, 'alter_settings' ), 10, 2 );
28
29 add_filter( 'merchant_module_shortcode_error_message_html', array( $this, 'shortcode_error_message' ), 10, 2 );
30
31 // Custom CSS.
32 add_filter( 'merchant_custom_css', array( $this, 'frontend_custom_css' ) );
33 }
34
35 /**
36 * Remove Divi shortcodes from description.
37 *
38 * @param $description
39 *
40 * @return array|string|string[]|null
41 */
42 public function quick_view_description( $description ) {
43 return $this->et_strip_shortcodes( $description );
44 }
45
46 /**
47 * For some reason in edit mode it can't detect is_singular( 'product' ) or is_product() tag and shows the error message.
48 *
49 * In that case change the error message.
50 *
51 * @param $content
52 * @param $module_id
53 *
54 * @return mixed|string
55 */
56 public function shortcode_error_message( $content, $module_id ) {
57 // Todo: check other way to find if current page is product page and return custom message. is_singular( 'product' ) or is_product() doesn't work
58 if ( function_exists( 'is_et_pb_preview' ) && is_et_pb_preview() ) {
59 return '<div class="merchant-shortcode-wrong-placement">' . esc_html__( 'Please view the product page to see this content.', 'merchant' ) . '</div>';
60 }
61
62 return $content;
63 }
64
65 /**
66 * Modify settings.
67 *
68 * @param $settings
69 * @param $module_id
70 *
71 * @return mixed
72 */
73 public function alter_settings( $settings, $module_id ) {
74 if ( $module_id === 'quick-view' ) {
75 // $settings['description_style'] = 'short';
76 }
77
78 return $settings;
79 }
80
81 /**
82 * Frontend custom CSS.
83 *
84 * @param string $css The custom CSS.
85 * @return string $css The custom CSS.
86 */
87 public function frontend_custom_css( $css ) {
88 if ( is_cart() ) {
89 $css .= '
90 .woocommerce .merchant-cart-offers .cart-item-offer__container .add-to-cart .add-to-cart-button {
91 font-size: 8px !important;
92 line-height: 1.6 !important;
93 font-weight: 700 !important;
94 }
95 ';
96 }
97
98 // Quick View
99 if ( Merchant_Modules::is_module_active( Merchant_Quick_View::MODULE_ID ) ) {
100 $css .= '
101 .merchant-quick-view-button:after {
102 content: none !important;
103 }
104 ';
105 }
106
107 if ( merchant_is_pro_active() ) {
108
109 // Variation Swatches
110 if ( Merchant_Modules::is_module_active( Merchant_Stock_Scarcity::MODULE_ID ) ) {
111 $css .= '
112 .merchant-variation-text:after {
113 content: none !important;
114 }
115 ';
116 }
117
118 // Wishlist
119 if ( Merchant_Modules::is_module_active( Merchant_Wishlist::MODULE_ID ) ) {
120 $css .= '
121 .single-product .merchant-wishlist-button {
122 position: static;
123 }
124 .single-product li .merchant-wishlist-button {
125 position: absolute;
126 }
127 ';
128 }
129
130 // Wishlist
131 if ( Merchant_Modules::is_module_active( Merchant_Size_Chart::MODULE_ID ) ) {
132 $css .= '
133 table.merchant-product-size-chart-modal-table {
134 width: 100%;
135 }
136 ';
137 }
138 }
139
140 return $css;
141 }
142
143 /**
144 * For some reason Divi's et_strip_shortcodes giving error in AJAX.
145 *
146 * So re-defining the function here
147 *
148 * @param $content
149 * @param $truncate_post_based_shortcodes_only
150 *
151 * @return array|string|string[]|null
152 */
153 public function et_strip_shortcodes( $content, $truncate_post_based_shortcodes_only = false ) {
154 global $shortcode_tags;
155
156 $content = trim( $content );
157
158 $strip_content_shortcodes = array(
159 'et_pb_code',
160 'et_pb_fullwidth_code',
161 'et_pb_social_media_follow_network',
162 );
163
164 // list of post-based shortcodes.
165 if ( $truncate_post_based_shortcodes_only ) {
166 $strip_content_shortcodes = array(
167 'et_pb_post_slider',
168 'et_pb_fullwidth_post_slider',
169 'et_pb_blog',
170 'et_pb_comments',
171 );
172 }
173
174 foreach ( $strip_content_shortcodes as $shortcode_name ) {
175 $regex = sprintf(
176 '(\[%1$s[^\]]*\][^\[]*\[\/%1$s\]|\[%1$s[^\]]*\])',
177 esc_html( $shortcode_name )
178 );
179
180 $content = preg_replace( $regex, '', $content );
181 }
182
183 // do not proceed if we need to truncate post-based shortcodes only.
184 if ( $truncate_post_based_shortcodes_only ) {
185 return $content;
186 }
187
188 $shortcode_tag_names = array();
189 foreach ( $shortcode_tags as $shortcode_tag_name => $shortcode_tag_cb ) {
190 if ( 0 !== strpos( $shortcode_tag_name, 'et_pb_' ) ) {
191 continue;
192 }
193
194 $shortcode_tag_names[] = $shortcode_tag_name;
195 }
196
197 $et_shortcodes = implode( '|', $shortcode_tag_names );
198
199 $regex_opening_shortcodes = sprintf( '(\[(%1$s)[^\]]+\])', esc_html( $et_shortcodes ) );
200 $regex_closing_shortcodes = sprintf( '(\[\/(%1$s)\])', esc_html( $et_shortcodes ) );
201
202 $content = preg_replace( $regex_opening_shortcodes, '', $content );
203 $content = preg_replace( $regex_closing_shortcodes, '', $content );
204
205 return $content;
206 }
207 }
208
209 add_action( 'init', function() {
210 new Merchant_Divi_Theme();
211 } );
212 }
213