| @@ -16,17 +16,17 @@ | ||
| 16 | 16 | |
| 17 | 17 | public function __construct() { |
| 18 | 18 | add_action( 'wp_enqueue_scripts', [ $this, 'enqueue' ] ); |
| 19 | 19 | |
| 20 | - // Gallery Plugin Support rtwpvg_disable_enqueue_scripts. | |
| 20 | + // Gallery Plugin Support rtwpvg_disable_enqueue_scripts | |
| 21 | 21 | add_filter( 'rtwpvg_disable_enqueue_scripts', '__return_false', 11 ); |
| 22 | 22 | |
| 23 | 23 | // Template. |
| 24 | 24 | |
| 25 | - add_action( 'rtsb/modules/quick_view/frontend/display', [ $this, 'button_hook' ] ); | |
| 26 | - // Add do_action( 'rtsb/modules/quick_view/frontend/display' ); for display anywhere. | |
| 25 | + add_action( 'rtsb/modules/quick_view/frontend/display', [ $this, 'button_hook' ] ); | |
| 26 | + // Add do_action( 'rtsb/modules/quick_view/frontend/display' ); for display anywhere. | |
| 27 | 27 | |
| 28 | - add_action( 'rtsb/modules/quick_view/print_button', [ $this, 'print_button' ] ); | |
| 28 | + add_action( 'rtsb/modules/quick_view/print_button', [ $this, 'print_button' ] ); | |
| 29 | 29 | |
| 30 | 30 | // Load action for product template. |
| 31 | 31 | $this->quick_view_action_template(); |
| 32 | 32 | |
| @@ -38,8 +38,9 @@ | ||
| 38 | 38 | |
| 39 | 39 | add_action( 'wp_ajax_nopriv_rtsb_load_product_quick_view', [ $this, 'product_quick_view_ajax' ] ); |
| 40 | 40 | |
| 41 | 41 | $this->attach_button(); |
| 42 | + | |
| 42 | 43 | } |
| 43 | 44 | |
| 44 | 45 | |
| 45 | 46 | /** |
| @@ -61,20 +62,21 @@ | ||
| 61 | 62 | add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_price', 15 ); |
| 62 | 63 | add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_excerpt', 20 ); |
| 63 | 64 | add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_add_to_cart', 25 ); |
| 64 | 65 | add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_meta', 30 ); |
| 66 | + | |
| 65 | 67 | } |
| 66 | 68 | |
| 67 | 69 | public function product_quick_view_ajax() { |
| 68 | - $product_id = isset( $_REQUEST['product_id'] ) ? absint( $_REQUEST['product_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 70 | + $product_id = absint( $_REQUEST['product_id'] ); | |
| 69 | 71 | |
| 70 | - if ( empty( $product_id ) || 'publish' !== get_post_status( $product_id ) ) { | |
| 72 | + if ( empty( $product_id ) ) { | |
| 71 | 73 | wp_send_json_error( esc_html__( 'Product Id not found', 'shopbuilder' ) ); |
| 72 | 74 | } |
| 73 | 75 | |
| 74 | 76 | global $sitepress; |
| 75 | 77 | |
| 76 | - $lang = isset( $_REQUEST['lang'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['lang'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 78 | + $lang = isset( $_REQUEST['lang'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['lang'] ) ) : ''; | |
| 77 | 79 | if ( defined( 'ICL_LANGUAGE_CODE' ) && $lang && isset( $sitepress ) ) { |
| 78 | 80 | $sitepress->switch_lang( $lang, true ); |
| 79 | 81 | } |
| 80 | 82 | |
| @@ -81,16 +83,22 @@ | ||
| 81 | 83 | // Set the main wp query for the product. |
| 82 | 84 | wp( 'p=' . $product_id . '&post_type=product' ); |
| 83 | 85 | |
| 84 | 86 | // Remove product thumbnails gallery. |
| 85 | - if ( defined( 'RTWPVG_VERSION' ) ) { | |
| 87 | + if ( defined('RTWPVG_VERSION') ) { | |
| 86 | 88 | remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 ); |
| 87 | 89 | } |
| 88 | - if ( ! defined( 'RTWPVG_VERSION' ) ) { | |
| 89 | - //add_action( 'woocommerce_product_thumbnails', [ $this, 'woocommerce_product_thumbnails_before' ], 1 ); | |
| 90 | - //add_action( 'woocommerce_product_thumbnails', [ $this, 'woocommerce_product_thumbnails_after' ], 25 ); | |
| 90 | + if ( ! defined('RTWPVG_VERSION') ) { | |
| 91 | + add_action( 'woocommerce_product_thumbnails', [ $this, 'woocommerce_product_thumbnails_before' ], 1 ); | |
| 92 | + add_action( 'woocommerce_product_thumbnails', [ $this, 'woocommerce_product_thumbnails_after'], 25 ); | |
| 91 | 93 | } |
| 92 | - | |
| 94 | + // Change template for variable products. | |
| 95 | + // if ( isset( $GLOBALS['yith_wccl'] ) ) { | |
| 96 | + // $GLOBALS['yith_wccl']->obj = new YITH_WCCL_Frontend(); | |
| 97 | + // $GLOBALS['yith_wccl']->obj->override(); | |
| 98 | + // } elseif ( defined( 'YITH_WCCL_PREMIUM' ) && YITH_WCCL_PREMIUM && class_exists( 'YITH_WCCL_Frontend' ) ) { | |
| 99 | + // $attributes = YITH_WCCL_Frontend()->create_attributes_json( $product_id, true ); | |
| 100 | + // } | |
| 93 | 101 | ob_start(); |
| 94 | 102 | Fns::load_template( 'quick-view/content' ); |
| 95 | 103 | $html = ob_get_contents(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 96 | 104 | ob_end_clean(); |
| @@ -118,9 +126,9 @@ | ||
| 118 | 126 | 'hook' => 'woocommerce_after_shop_loop_item', |
| 119 | 127 | 'priority' => 15, |
| 120 | 128 | ], |
| 121 | 129 | 'custom' => [ |
| 122 | - 'hook' => Fns::get_option( 'modules', 'quick_view', 'loop_custom_hook_name', '' ), | |
| 130 | + 'hook' => Fns::get_option( 'modules', 'quick_view', 'loop_custom_hook_name', '' ), | |
| 123 | 131 | 'priority' => Fns::get_option( 'modules', 'quick_view', 'loop_custom_hook_priority', '' ), |
| 124 | 132 | ], |
| 125 | 133 | ] |
| 126 | 134 | ); |
| @@ -148,10 +156,9 @@ | ||
| 148 | 156 | * Print "Add to compare" button |
| 149 | 157 | * |
| 150 | 158 | * @return void |
| 151 | 159 | */ |
| 152 | - public function woocommerce_product_thumbnails_before() { | |
| 153 | - ?> | |
| 160 | + public function woocommerce_product_thumbnails_before() { ?> | |
| 154 | 161 | <div class="rtsb-gallery-images-wrapper"> |
| 155 | 162 | <?php |
| 156 | 163 | } |
| 157 | 164 | /** |
| @@ -158,11 +165,9 @@ | ||
| 158 | 165 | * Print "Add to compare" button |
| 159 | 166 | * |
| 160 | 167 | * @return void |
| 161 | 168 | */ |
| 162 | - public function woocommerce_product_thumbnails_after() { | |
| 163 | - | |
| 164 | - ?> | |
| 169 | + public function woocommerce_product_thumbnails_after() { ?> | |
| 165 | 170 | </div> |
| 166 | 171 | <?php |
| 167 | 172 | } |
| 168 | 173 | |
| @@ -174,13 +179,12 @@ | ||
| 174 | 179 | public function button_hook() { |
| 175 | 180 | if ( ! apply_filters( 'rtsb/module/quick_view/show_button', true ) ) { |
| 176 | 181 | return; |
| 177 | 182 | } |
| 178 | - global $product; | |
| 179 | - if ( $product instanceof WC_Product ) { | |
| 180 | - do_action( 'rtsb/modules/quick_view/print_button', $product->get_id() ); | |
| 181 | - } | |
| 182 | - | |
| 183 | + global $product; | |
| 184 | + if( $product instanceof WC_Product ) { | |
| 185 | + do_action('rtsb/modules/quick_view/print_button', $product->get_id()); | |
| 186 | + } | |
| 183 | 187 | } |
| 184 | 188 | |
| 185 | 189 | |
| 186 | 190 | /** |
| @@ -188,25 +192,25 @@ | ||
| 188 | 192 | */ |
| 189 | 193 | public function print_button( $product_id = 0 ) { |
| 190 | 194 | global $product; |
| 191 | 195 | |
| 192 | - if ( ! $product instanceof WC_Product && $product_id ) { | |
| 193 | - $product = wc_get_product( $product_id ); | |
| 196 | + // product object. | |
| 197 | + $current_product = $product_id ? wc_get_product( $product_id ) : false; | |
| 198 | + $current_product = $current_product ?: $product; | |
| 199 | + | |
| 200 | + if ( ! $current_product instanceof WC_Product ) { | |
| 201 | + return ''; | |
| 194 | 202 | } |
| 195 | 203 | |
| 196 | - // if ( ! $current_product instanceof WC_Product ) { | |
| 197 | - // return ''; | |
| 198 | - // } | |
| 199 | - | |
| 200 | 204 | $classes = []; // button class. |
| 201 | - $button_text = Fns::get_option( 'modules', 'quick_view', 'button_text', esc_html__( 'Quick View', 'shopbuilder' ) ); | |
| 205 | + $button_text = Fns::get_option( 'modules', 'quick_view', 'button_text', esc_html__( 'Quick View', 'shopbuilder' ) ); | |
| 202 | 206 | |
| 203 | - $icon_html = '<i class="rtsb-icon rtsb-icon-eye"></i>'; | |
| 207 | + $icon_html = '<i class="rtsb-icon rtsb-icon-eye"></i>'; | |
| 204 | 208 | // get product type. |
| 205 | - $product_type = $product->get_type(); | |
| 209 | + $product_type = $current_product->get_type(); | |
| 206 | 210 | $params = [ |
| 207 | 211 | 'classes' => $classes, |
| 208 | - 'product_id' => $product->get_id(), | |
| 212 | + 'product_id' => $current_product->get_id(), | |
| 209 | 213 | 'product_type' => $product_type, |
| 210 | 214 | 'button_text' => $button_text, |
| 211 | 215 | 'left_text' => apply_filters( 'rtsb/module/quick_view/button_left_text', '' ), |
| 212 | 216 | 'right_text' => apply_filters( 'rtsb/module/quick_view/button_right_text', '' ), |
| @@ -228,31 +232,21 @@ | ||
| 228 | 232 | * |
| 229 | 233 | * @return string [HTML] |
| 230 | 234 | */ |
| 231 | 235 | public function button_shortcode( $atts, $content = '' ) { |
| 232 | - global $product; | |
| 236 | + $this->enqueue(); | |
| 237 | + global $product; | |
| 233 | 238 | if ( ! $product instanceof WC_Product ) { |
| 234 | 239 | return ''; |
| 235 | 240 | } |
| 236 | 241 | ob_start(); |
| 237 | 242 | |
| 238 | - do_action( 'rtsb/modules/quick_view/print_button', $product->get_id() ); | |
| 243 | + do_action( 'rtsb/modules/quick_view/print_button', $product->get_id() ); | |
| 239 | 244 | |
| 240 | - return ob_get_clean(); | |
| 245 | + return ob_get_clean(); | |
| 241 | 246 | } |
| 242 | 247 | |
| 243 | 248 | public function enqueue() { |
| 244 | - | |
| 245 | - wp_enqueue_style( 'elementor-icons-fa-regular' ); | |
| 246 | - | |
| 247 | - wp_enqueue_style( 'elementor-icons-fa-solid' ); | |
| 248 | - wp_enqueue_style( 'elementor-icons-shared-0' ); | |
| 249 | - // wp_enqueue_style( 'elementor-frontend' ); | |
| 250 | - | |
| 251 | - if ( ! class_exists('WooProductVariationGallery') && current_theme_supports( 'wc-product-gallery-slider' ) ) { | |
| 252 | - wp_enqueue_script( 'flexslider' ); | |
| 253 | - } | |
| 254 | - | |
| 255 | 249 | wp_enqueue_script( 'wc-add-to-cart-variation' ); |
| 256 | 250 | if ( version_compare( WC()->version, '3.0.0', '>=' ) ) { |
| 257 | 251 | if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) { |
| 258 | 252 | wp_enqueue_script( 'zoom' ); |
| @@ -277,9 +271,9 @@ | ||
| 277 | 271 | ], |
| 278 | 272 | RTSB_VERSION, |
| 279 | 273 | true |
| 280 | 274 | ); |
| 281 | - wp_enqueue_style( 'rtsb-modules' ); | |
| 275 | + wp_enqueue_style( 'rtsb-modules' ); | |
| 282 | 276 | wp_enqueue_script( 'rtsb-quick-view' ); |
| 283 | 277 | |
| 284 | 278 | // Allow user to load custom style and scripts! |
| 285 | 279 | do_action( 'rtsb/modules/quick_view/custom_scripts' ); |
| @@ -307,9 +301,9 @@ | ||
| 307 | 301 | * @return string Filtered HTML. |
| 308 | 302 | */ |
| 309 | 303 | public function add_button_for_block( $item_html, $data, $product ) { |
| 310 | 304 | // Add the link "Add to wishlist" in the loop. |
| 311 | - $shop_btn_position = Fns::get_option( 'modules', 'quick_view', 'loop_btn_position', 'after_add_to_cart' ); | |
| 305 | + $shop_btn_position = Fns::get_option( 'modules', 'quick_view', 'loop_btn_position', 'after_add_to_cart' ); | |
| 312 | 306 | ob_start(); |
| 313 | 307 | $this->print_button( $product->get_id() ); |
| 314 | 308 | $button = ob_get_clean(); |
| 315 | 309 | $parts = []; |