inc/compatibility
class-merchant-astra-theme.php
1.1 KB
1 month ago
class-merchant-avada-theme.php
918 B
1 month ago
class-merchant-blocksy-theme.php
4.8 KB
1 month ago
class-merchant-botiga-theme.php
4.4 KB
1 month ago
class-merchant-breakdance-builder.php
12.8 KB
1 month ago
class-merchant-bricks-builder.php
1.5 KB
1 month ago
class-merchant-divi-theme.php
5.9 KB
1 month ago
class-merchant-elementor-builder.php
7.3 KB
1 month ago
class-merchant-flatsome-theme.php
948 B
1 month ago
class-merchant-kadence-theme.php
938 B
1 month ago
class-merchant-oceanwp-theme.php
1.5 KB
1 month ago
class-merchant-ohio-theme.php
26.1 KB
1 month ago
class-merchant-twenty-twenty-four-theme.php
1.1 KB
1 month ago
class-merchant-woo-multi-currency.php
4.7 KB
1 month ago
class-merchant-woo-payments-plugin.php
1.6 KB
1 month ago
class-merchant-divi-theme.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 2.3.1, at inc/compatibility/class-merchant-divi-theme.php
| 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 | add_filter( 'merchant_real_time_search_product_description', array( $this, 'remove_shortcode_product_description' ) ); |
| 32 | |
| 33 | // Custom CSS. |
| 34 | add_filter( 'merchant_custom_css', array( $this, 'frontend_custom_css' ) ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Remove Divi shortcodes from description. |
| 39 | * |
| 40 | * @param $description |
| 41 | * |
| 42 | * @return array|string|string[]|null |
| 43 | */ |
| 44 | public function quick_view_description( $description ) { |
| 45 | return $this->et_strip_shortcodes( $description ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Remove Divi shortcodes from search Real-time search results product description. |
| 50 | * |
| 51 | * @param $content |
| 52 | * |
| 53 | * @return array|string|string[]|null |
| 54 | */ |
| 55 | public function remove_shortcode_product_description( $content ) { |
| 56 | return $this->et_strip_shortcodes( $content ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * For some reason in edit mode it can't detect is_singular( 'product' ) or is_product() tag and shows the error message. |
| 61 | * |
| 62 | * In that case change the error message. |
| 63 | * |
| 64 | * @param $content |
| 65 | * @param $module_id |
| 66 | * |
| 67 | * @return mixed|string |
| 68 | */ |
| 69 | public function shortcode_error_message( $content, $module_id ) { |
| 70 | // 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 |
| 71 | if ( function_exists( 'is_et_pb_preview' ) && is_et_pb_preview() ) { |
| 72 | return '<div class="merchant-shortcode-wrong-placement">' . esc_html__( 'Please view the product page to see this content.', 'merchant' ) . '</div>'; |
| 73 | } |
| 74 | |
| 75 | return $content; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Modify settings. |
| 80 | * |
| 81 | * @param $settings |
| 82 | * @param $module_id |
| 83 | * |
| 84 | * @return mixed |
| 85 | */ |
| 86 | public function alter_settings( $settings, $module_id ) { |
| 87 | if ( $module_id === 'quick-view' ) { |
| 88 | // $settings['description_style'] = 'short'; |
| 89 | } |
| 90 | |
| 91 | return $settings; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Frontend custom CSS. |
| 96 | * |
| 97 | * @param string $css The custom CSS. |
| 98 | * @return string $css The custom CSS. |
| 99 | */ |
| 100 | public function frontend_custom_css( $css ) { |
| 101 | if ( is_cart() ) { |
| 102 | $css .= ' |
| 103 | .woocommerce .merchant-cart-offers .cart-item-offer__container .add-to-cart .add-to-cart-button { |
| 104 | font-size: 8px !important; |
| 105 | line-height: 1.6 !important; |
| 106 | font-weight: 700 !important; |
| 107 | } |
| 108 | '; |
| 109 | } |
| 110 | |
| 111 | // Quick View |
| 112 | if ( Merchant_Modules::is_module_active( Merchant_Quick_View::MODULE_ID ) ) { |
| 113 | $css .= ' |
| 114 | .merchant-quick-view-button:after { |
| 115 | content: none !important; |
| 116 | } |
| 117 | '; |
| 118 | } |
| 119 | |
| 120 | if ( merchant_is_pro_active() ) { |
| 121 | |
| 122 | // Variation Swatches |
| 123 | if ( Merchant_Modules::is_module_active( Merchant_Stock_Scarcity::MODULE_ID ) ) { |
| 124 | $css .= ' |
| 125 | .merchant-variation-text:after { |
| 126 | content: none !important; |
| 127 | } |
| 128 | '; |
| 129 | } |
| 130 | |
| 131 | // Wishlist |
| 132 | if ( Merchant_Modules::is_module_active( Merchant_Wishlist::MODULE_ID ) ) { |
| 133 | $css .= ' |
| 134 | .single-product .merchant-wishlist-button { |
| 135 | position: static; |
| 136 | } |
| 137 | .single-product li .merchant-wishlist-button { |
| 138 | position: absolute; |
| 139 | } |
| 140 | '; |
| 141 | } |
| 142 | |
| 143 | // Wishlist |
| 144 | if ( Merchant_Modules::is_module_active( Merchant_Size_Chart::MODULE_ID ) ) { |
| 145 | $css .= ' |
| 146 | table.merchant-product-size-chart-modal-table { |
| 147 | width: 100%; |
| 148 | } |
| 149 | '; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | return $css; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * For some reason Divi's et_strip_shortcodes giving error in AJAX. |
| 158 | * |
| 159 | * So re-defining the function here |
| 160 | * |
| 161 | * @param $content |
| 162 | * @param $truncate_post_based_shortcodes_only |
| 163 | * |
| 164 | * @return array|string|string[]|null |
| 165 | */ |
| 166 | public function et_strip_shortcodes( $content, $truncate_post_based_shortcodes_only = false ) { |
| 167 | global $shortcode_tags; |
| 168 | |
| 169 | $content = trim( $content ); |
| 170 | |
| 171 | $strip_content_shortcodes = array( |
| 172 | 'et_pb_code', |
| 173 | 'et_pb_fullwidth_code', |
| 174 | 'et_pb_social_media_follow_network', |
| 175 | 'et_pb_section', |
| 176 | 'et_pb_row', |
| 177 | 'et_pb_row_inner', |
| 178 | ); |
| 179 | |
| 180 | // list of post-based shortcodes. |
| 181 | if ( $truncate_post_based_shortcodes_only ) { |
| 182 | $strip_content_shortcodes = array( |
| 183 | 'et_pb_post_slider', |
| 184 | 'et_pb_fullwidth_post_slider', |
| 185 | 'et_pb_blog', |
| 186 | 'et_pb_comments', |
| 187 | ); |
| 188 | } |
| 189 | |
| 190 | foreach ( $strip_content_shortcodes as $shortcode_name ) { |
| 191 | $regex = sprintf( |
| 192 | '(\[%1$s[^\]]*\][^\[]*\[\/%1$s\]|\[%1$s[^\]]*\])', |
| 193 | esc_html( $shortcode_name ) |
| 194 | ); |
| 195 | |
| 196 | $content = preg_replace( $regex, '', $content ); |
| 197 | } |
| 198 | |
| 199 | // do not proceed if we need to truncate post-based shortcodes only. |
| 200 | if ( $truncate_post_based_shortcodes_only ) { |
| 201 | return $content; |
| 202 | } |
| 203 | |
| 204 | $shortcode_tag_names = array(); |
| 205 | foreach ( $shortcode_tags as $shortcode_tag_name => $shortcode_tag_cb ) { |
| 206 | if ( 0 !== strpos( $shortcode_tag_name, 'et_pb_' ) ) { |
| 207 | continue; |
| 208 | } |
| 209 | |
| 210 | $shortcode_tag_names[] = $shortcode_tag_name; |
| 211 | } |
| 212 | |
| 213 | $et_shortcodes = implode( '|', $shortcode_tag_names ); |
| 214 | |
| 215 | $regex_opening_shortcodes = sprintf( '(\[(%1$s)[^\]]+\])', esc_html( $et_shortcodes ) ); |
| 216 | $regex_closing_shortcodes = sprintf( '(\[\/(%1$s)\])', esc_html( $et_shortcodes ) ); |
| 217 | |
| 218 | $content = preg_replace( $regex_opening_shortcodes, '', $content ); |
| 219 | $content = preg_replace( $regex_closing_shortcodes, '', $content ); |
| 220 | |
| 221 | return $content; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | add_action( 'init', function() { |
| 226 | new Merchant_Divi_Theme(); |
| 227 | } ); |
| 228 | } |
| 229 |