| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Elementor Builder compatibility layer |
| 9 |
*/ |
| 10 |
if ( ! class_exists( 'Merchant_Elementor_Builder' ) ) { |
| 11 |
class Merchant_Elementor_Builder { |
| 12 |
|
| 13 |
/** |
| 14 |
* Constructor. |
| 15 |
*/ |
| 16 |
public function __construct() { |
| 17 |
if ( ( is_admin() && ! wp_doing_ajax() ) || ! merchant_is_elementor_active() ) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Elementor Pro Hook for Single Product Page when using Template |
| 23 |
* |
| 24 |
* Single Product Template works for Pro only |
| 25 |
* |
| 26 |
* Using `woocommerce_after_add_to_cart_form` as other hooks that use inside each module doesn't seem to be working. |
| 27 |
*/ |
| 28 |
add_action( 'elementor/theme/before_do_single', function( $locations_manager ) { |
| 29 |
|
| 30 |
// Payment Logos |
| 31 |
if ( Merchant_Modules::is_module_active( Merchant_Payment_Logos::MODULE_ID ) ) { |
| 32 |
$pl = Merchant_Modules::get_module( Merchant_Payment_Logos::MODULE_ID ); |
| 33 |
if ( $pl instanceof Merchant_Payment_Logos ) { |
| 34 |
add_action( 'woocommerce_after_add_to_cart_form', array( $pl, 'payment_logos_output' ), 15 ); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
// Trust Badges |
| 39 |
if ( Merchant_Modules::is_module_active( Merchant_Trust_Badges::MODULE_ID ) ) { |
| 40 |
$tb = Merchant_Modules::get_module( Merchant_Trust_Badges::MODULE_ID ); |
| 41 |
if ( $tb instanceof Merchant_Trust_Badges ) { |
| 42 |
add_action( 'woocommerce_after_add_to_cart_form', array( $tb, 'trust_badges_output' ), 20 ); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
if ( merchant_is_pro_active() ) { |
| 47 |
|
| 48 |
// Wishlist |
| 49 |
if ( Merchant_Modules::is_module_active( Merchant_Wishlist::MODULE_ID ) ) { |
| 50 |
// Display on single product. |
| 51 |
$display_on_single_product = Merchant_Admin_Options::get( Merchant_Wishlist::MODULE_ID, 'display_on_single_product', true ); |
| 52 |
if ( $display_on_single_product ) { |
| 53 |
$wishlist = new Merchant_Pro_Wishlist( Merchant_Modules::get_module( Merchant_Wishlist::MODULE_ID ) );; |
| 54 |
|
| 55 |
add_action( 'woocommerce_after_add_to_cart_form', array( $wishlist, 'wishlist_link' ) ); |
| 56 |
//add_action( 'elementor/element/woocommerce-product-content/section_style/after_section_end', array( $wishlist, 'wishlist_link' ), 99 ); |
| 57 |
//add_action( 'elementor/element/woocommerce-product-meta/section_product_meta_style/after_section_end', array( $wishlist, 'wishlist_link' ) ); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
// Product Brand Image |
| 62 |
if ( Merchant_Modules::is_module_active( Merchant_Product_Brand_Image::MODULE_ID ) ) { |
| 63 |
$pbi = new Merchant_Pro_Product_Brand_Image( Merchant_Modules::get_module( Merchant_Product_Brand_Image::MODULE_ID ) ); |
| 64 |
add_action( 'woocommerce_after_add_to_cart_form', array( $pbi, 'brand_image' ), 25 ); |
| 65 |
} |
| 66 |
|
| 67 |
// Product Navigation Links |
| 68 |
if ( Merchant_Modules::is_module_active( Merchant_Product_Navigation_Links::MODULE_ID ) ) { |
| 69 |
$pnl = new Merchant_Pro_Product_Navigation_Links( Merchant_Modules::get_module( Merchant_Product_Navigation_Links::MODULE_ID ) ); |
| 70 |
add_action( 'woocommerce_after_add_to_cart_form', array( $pnl, 'render_output_html' ), 100 ); |
| 71 |
} |
| 72 |
} |
| 73 |
} ); |
| 74 |
|
| 75 |
add_filter( 'merchant_enqueue_module_styles', array( $this, 'should_enqueue_styles' ), 10, 2 ); |
| 76 |
add_filter( 'merchant_enqueue_module_scripts', array( $this, 'should_enqueue_scripts' ), 10, 2 ); |
| 77 |
|
| 78 |
// Custom CSS. |
| 79 |
add_filter( 'merchant_custom_css', array( $this, 'frontend_custom_css' ) ); |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Determines whether to enqueue styles for modules. |
| 84 |
* |
| 85 |
* @param $enqueue |
| 86 |
* @param $module |
| 87 |
* |
| 88 |
* @return boolean |
| 89 |
*/ |
| 90 |
public function should_enqueue_styles( $enqueue, $module ) { |
| 91 |
$module_id = $module->module_id ?? ''; |
| 92 |
|
| 93 |
if ( \Elementor\Plugin::$instance->preview->is_preview_mode() && Merchant_Modules::is_module_active( $module_id ) ) { |
| 94 |
return true; |
| 95 |
} |
| 96 |
|
| 97 |
// Todo: check if required for other modules as well |
| 98 |
if ( ! \Elementor\Plugin::$instance->preview->is_preview_mode() && Merchant_Modules::is_module_active( $module_id ) && ( $module_id === 'wishlist' ) ) { |
| 99 |
global $post; |
| 100 |
|
| 101 |
if ( empty( $post ) ) { |
| 102 |
return $enqueue; |
| 103 |
} |
| 104 |
|
| 105 |
$elementor_data = get_post_meta( $post->ID, '_elementor_data', true ); |
| 106 |
if ( |
| 107 |
$elementor_data && |
| 108 |
( strpos( $elementor_data, 'woocommerce-products' ) !== false || strpos( $elementor_data, 'wc-products' ) !== false ) ) { |
| 109 |
return true; |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
return $enqueue; |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Determines whether to enqueue scripts for modules. |
| 118 |
* |
| 119 |
* @param $enqueue |
| 120 |
* @param $module |
| 121 |
* |
| 122 |
* @return mixed|true |
| 123 |
*/ |
| 124 |
public function should_enqueue_scripts( $enqueue, $module ) { |
| 125 |
$module_id = $module->module_id ?? ''; |
| 126 |
|
| 127 |
if ( \Elementor\Plugin::$instance->preview->is_preview_mode() && Merchant_Modules::is_module_active( $module_id ) ) { |
| 128 |
return true; |
| 129 |
} |
| 130 |
|
| 131 |
// Todo: check if required for other modules as well |
| 132 |
if ( ! \Elementor\Plugin::$instance->preview->is_preview_mode() && Merchant_Modules::is_module_active( $module_id ) && ( $module_id === 'wishlist' ) ) { |
| 133 |
global $post; |
| 134 |
|
| 135 |
if ( empty( $post ) ) { |
| 136 |
return $enqueue; |
| 137 |
} |
| 138 |
|
| 139 |
$elementor_data = get_post_meta( $post->ID, '_elementor_data', true ); |
| 140 |
if ( |
| 141 |
$elementor_data && |
| 142 |
( strpos( $elementor_data, 'woocommerce-products' ) !== false || strpos( $elementor_data, 'wc-products' ) !== false ) ) { |
| 143 |
return true; |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
return $enqueue; |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Frontend custom CSS. |
| 152 |
* |
| 153 |
* @param string $css The custom CSS. |
| 154 |
* @return string $css The custom CSS. |
| 155 |
*/ |
| 156 |
public function frontend_custom_css( $css ) { |
| 157 |
$css .= Merchant_Side_Cart::get_module_custom_css(); |
| 158 |
|
| 159 |
// Quick View |
| 160 |
if ( Merchant_Modules::is_module_active( Merchant_Quick_View::MODULE_ID ) ) { |
| 161 |
$css .= ' |
| 162 |
.merchant-quick-view-button { |
| 163 |
padding: .618em 1em !important; |
| 164 |
} |
| 165 |
'; |
| 166 |
} |
| 167 |
|
| 168 |
// Payment Logos |
| 169 |
if ( Merchant_Modules::is_module_active( Merchant_Payment_Logos::MODULE_ID ) ) { |
| 170 |
$css .= ' |
| 171 |
.single-product li .merchant-payment-logos { |
| 172 |
display: none !important; |
| 173 |
} |
| 174 |
'; |
| 175 |
} |
| 176 |
|
| 177 |
// Trust Badges |
| 178 |
if ( Merchant_Modules::is_module_active( Merchant_Trust_Badges::MODULE_ID ) ) { |
| 179 |
$css .= ' |
| 180 |
.single-product li .merchant-trust-badges { |
| 181 |
display: none !important; |
| 182 |
} |
| 183 |
'; |
| 184 |
} |
| 185 |
|
| 186 |
if ( merchant_is_pro_active() ) { |
| 187 |
|
| 188 |
// Variation Swatches |
| 189 |
if ( Merchant_Modules::is_module_active( Merchant_Stock_Scarcity::MODULE_ID ) ) { |
| 190 |
$css .= ' |
| 191 |
.single-product form.cart { |
| 192 |
flex-wrap: wrap !important; |
| 193 |
} |
| 194 |
'; |
| 195 |
} |
| 196 |
|
| 197 |
// Wishlist |
| 198 |
if ( Merchant_Modules::is_module_active( Merchant_Wishlist::MODULE_ID ) ) { |
| 199 |
$css .= ' |
| 200 |
.single-product .merchant-wishlist-button { |
| 201 |
position: static; |
| 202 |
} |
| 203 |
.single-product li .merchant-wishlist-button { |
| 204 |
position: absolute; |
| 205 |
} |
| 206 |
|
| 207 |
.merchant-wishlist-button ~ .merchant-product-swatches .merchant-wishlist-button { |
| 208 |
display: none !important; |
| 209 |
} |
| 210 |
'; |
| 211 |
} |
| 212 |
|
| 213 |
// Product Brand Image |
| 214 |
if ( Merchant_Modules::is_module_active( Merchant_Product_Brand_Image::MODULE_ID ) ) { |
| 215 |
$css .= ' |
| 216 |
.single-product li .merchant-product-brand-image { |
| 217 |
display: none !important; |
| 218 |
} |
| 219 |
'; |
| 220 |
} |
| 221 |
|
| 222 |
// Product Navigation Links |
| 223 |
if ( Merchant_Modules::is_module_active( Merchant_Product_Navigation_Links::MODULE_ID ) ) { |
| 224 |
$css .= ' |
| 225 |
.single-product li .merchant-product-navigation { |
| 226 |
display: none !important; |
| 227 |
} |
| 228 |
'; |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
return $css; |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
add_action( 'init', function() { |
| 237 |
new Merchant_Elementor_Builder(); |
| 238 |
} ); |
| 239 |
} |
| 240 |
|