| @@ -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,9 +38,8 @@ | ||
| 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 | - | |
| 43 | 42 | } |
| 44 | 43 | |
| 45 | 44 | |
| 46 | 45 | /** |
| @@ -50,9 +49,9 @@ | ||
| 50 | 49 | * @return void |
| 51 | 50 | * @since 1.0.0 |
| 52 | 51 | */ |
| 53 | 52 | public function quick_view_action_template() { |
| 54 | - | |
| 53 | + wp_enqueue_style( 'elementor-frontend' ); | |
| 55 | 54 | // Image. |
| 56 | 55 | add_action( 'rtsb/wcqv/product/image', 'woocommerce_show_product_sale_flash', 10 ); |
| 57 | 56 | add_action( 'rtsb/wcqv/product/image', 'woocommerce_show_product_images', 20 ); |
| 58 | 57 | |
| @@ -62,21 +61,20 @@ | ||
| 62 | 61 | add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_price', 15 ); |
| 63 | 62 | add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_excerpt', 20 ); |
| 64 | 63 | add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_add_to_cart', 25 ); |
| 65 | 64 | add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_meta', 30 ); |
| 66 | - | |
| 67 | 65 | } |
| 68 | 66 | |
| 69 | 67 | public function product_quick_view_ajax() { |
| 70 | - $product_id = absint( $_REQUEST['product_id'] ); | |
| 68 | + $product_id = isset( $_REQUEST['product_id'] ) ? absint( $_REQUEST['product_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 71 | 69 | |
| 72 | - if ( empty( $product_id ) ) { | |
| 70 | + if ( empty( $product_id ) || 'publish' !== get_post_status( $product_id ) ) { | |
| 73 | 71 | wp_send_json_error( esc_html__( 'Product Id not found', 'shopbuilder' ) ); |
| 74 | 72 | } |
| 75 | 73 | |
| 76 | 74 | global $sitepress; |
| 77 | 75 | |
| 78 | - $lang = isset( $_REQUEST['lang'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['lang'] ) ) : ''; | |
| 76 | + $lang = isset( $_REQUEST['lang'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['lang'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 79 | 77 | if ( defined( 'ICL_LANGUAGE_CODE' ) && $lang && isset( $sitepress ) ) { |
| 80 | 78 | $sitepress->switch_lang( $lang, true ); |
| 81 | 79 | } |
| 82 | 80 | |
| @@ -83,22 +81,16 @@ | ||
| 83 | 81 | // Set the main wp query for the product. |
| 84 | 82 | wp( 'p=' . $product_id . '&post_type=product' ); |
| 85 | 83 | |
| 86 | 84 | // Remove product thumbnails gallery. |
| 87 | - if ( defined('RTWPVG_VERSION') ) { | |
| 85 | + if ( defined( 'RTWPVG_VERSION' ) ) { | |
| 88 | 86 | remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 ); |
| 89 | 87 | } |
| 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 ); | |
| 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 ); | |
| 93 | 91 | } |
| 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 | - // } | |
| 92 | + | |
| 101 | 93 | ob_start(); |
| 102 | 94 | Fns::load_template( 'quick-view/content' ); |
| 103 | 95 | $html = ob_get_contents(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 104 | 96 | ob_end_clean(); |
| @@ -126,9 +118,9 @@ | ||
| 126 | 118 | 'hook' => 'woocommerce_after_shop_loop_item', |
| 127 | 119 | 'priority' => 15, |
| 128 | 120 | ], |
| 129 | 121 | 'custom' => [ |
| 130 | - 'hook' => Fns::get_option( 'modules', 'quick_view', 'loop_custom_hook_name', '' ), | |
| 122 | + 'hook' => Fns::get_option( 'modules', 'quick_view', 'loop_custom_hook_name', '' ), | |
| 131 | 123 | 'priority' => Fns::get_option( 'modules', 'quick_view', 'loop_custom_hook_priority', '' ), |
| 132 | 124 | ], |
| 133 | 125 | ] |
| 134 | 126 | ); |
| @@ -156,9 +148,10 @@ | ||
| 156 | 148 | * Print "Add to compare" button |
| 157 | 149 | * |
| 158 | 150 | * @return void |
| 159 | 151 | */ |
| 160 | - public function woocommerce_product_thumbnails_before() { ?> | |
| 152 | + public function woocommerce_product_thumbnails_before() { | |
| 153 | + ?> | |
| 161 | 154 | <div class="rtsb-gallery-images-wrapper"> |
| 162 | 155 | <?php |
| 163 | 156 | } |
| 164 | 157 | /** |
| @@ -165,9 +158,11 @@ | ||
| 165 | 158 | * Print "Add to compare" button |
| 166 | 159 | * |
| 167 | 160 | * @return void |
| 168 | 161 | */ |
| 169 | - public function woocommerce_product_thumbnails_after() { ?> | |
| 162 | + public function woocommerce_product_thumbnails_after() { | |
| 163 | + | |
| 164 | + ?> | |
| 170 | 165 | </div> |
| 171 | 166 | <?php |
| 172 | 167 | } |
| 173 | 168 | |
| @@ -179,12 +174,12 @@ | ||
| 179 | 174 | public function button_hook() { |
| 180 | 175 | if ( ! apply_filters( 'rtsb/module/quick_view/show_button', true ) ) { |
| 181 | 176 | return; |
| 182 | 177 | } |
| 183 | - global $product; | |
| 184 | - if( $product instanceof WC_Product ) { | |
| 185 | - do_action('rtsb/modules/quick_view/print_button', $product->get_id()); | |
| 186 | - } | |
| 178 | + global $product; | |
| 179 | + if ( $product instanceof WC_Product ) { | |
| 180 | + do_action( 'rtsb/modules/quick_view/print_button', $product->get_id() ); | |
| 181 | + } | |
| 187 | 182 | } |
| 188 | 183 | |
| 189 | 184 | |
| 190 | 185 | /** |
| @@ -192,29 +187,30 @@ | ||
| 192 | 187 | */ |
| 193 | 188 | public function print_button( $product_id = 0 ) { |
| 194 | 189 | global $product; |
| 195 | 190 | |
| 196 | - // product object. | |
| 197 | - $current_product = $product_id ? wc_get_product( $product_id ) : false; | |
| 198 | - $current_product = $current_product ?: $product; | |
| 191 | + if ( ! $product instanceof WC_Product && $product_id ) { | |
| 192 | + $product = wc_get_product( $product_id ); | |
| 193 | + } | |
| 199 | 194 | |
| 200 | - if ( ! $current_product instanceof WC_Product ) { | |
| 201 | - return ''; | |
| 202 | - } | |
| 195 | + // if ( ! $current_product instanceof WC_Product ) { | |
| 196 | + // return ''; | |
| 197 | + // } | |
| 203 | 198 | |
| 204 | 199 | $classes = []; // button class. |
| 205 | - $button_text = Fns::get_option( 'modules', 'quick_view', 'button_text', esc_html__( 'Quick View', 'shopbuilder' ) ); | |
| 200 | + $button_text = Fns::get_option( 'modules', 'quick_view', 'button_text', esc_html__( 'Quick View', 'shopbuilder' ) ); | |
| 206 | 201 | |
| 207 | - $icon_html = '<i class="rtsb-icon rtsb-icon-eye"></i>'; | |
| 202 | + $icon_html = '<i class="rtsb-icon rtsb-icon-eye"></i>'; | |
| 208 | 203 | // get product type. |
| 209 | - $product_type = $current_product->get_type(); | |
| 204 | + $product_type = $product->get_type(); | |
| 210 | 205 | $params = [ |
| 211 | - 'classes' => $classes, | |
| 212 | - 'product_id' => $current_product->get_id(), | |
| 213 | - 'product_type' => $product_type, | |
| 214 | - 'button_text' => $button_text, | |
| 215 | - 'left_text' => apply_filters( 'rtsb/module/quick_view/button_left_text', '' ), | |
| 216 | - 'right_text' => apply_filters( 'rtsb/module/quick_view/button_right_text', '' ), | |
| 206 | + 'classes' => $classes, | |
| 207 | + 'product_id' => $product->get_id(), | |
| 208 | + 'product_type' => $product_type, | |
| 209 | + 'button_text' => $button_text, | |
| 210 | + 'has_button_text' => ! empty( Fns::get_option( 'modules', 'quick_view', 'button_text', '' ) ), | |
| 211 | + 'left_text' => apply_filters( 'rtsb/module/quick_view/button_left_text', '' ), | |
| 212 | + 'right_text' => apply_filters( 'rtsb/module/quick_view/button_right_text', '' ), | |
| 217 | 213 | ]; |
| 218 | 214 | // let third party developer filter options. |
| 219 | 215 | $atts = apply_filters( 'rtsb/module/quick_view/button_params', $params ); |
| 220 | 216 | // set fragment options. |
| @@ -232,21 +228,31 @@ | ||
| 232 | 228 | * |
| 233 | 229 | * @return string [HTML] |
| 234 | 230 | */ |
| 235 | 231 | public function button_shortcode( $atts, $content = '' ) { |
| 236 | - $this->enqueue(); | |
| 237 | - global $product; | |
| 232 | + global $product; | |
| 238 | 233 | if ( ! $product instanceof WC_Product ) { |
| 239 | 234 | return ''; |
| 240 | 235 | } |
| 241 | 236 | ob_start(); |
| 242 | 237 | |
| 243 | - do_action( 'rtsb/modules/quick_view/print_button', $product->get_id() ); | |
| 238 | + do_action( 'rtsb/modules/quick_view/print_button', $product->get_id() ); | |
| 244 | 239 | |
| 245 | - return ob_get_clean(); | |
| 240 | + return ob_get_clean(); | |
| 246 | 241 | } |
| 247 | 242 | |
| 248 | 243 | 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 | + | |
| 249 | 255 | wp_enqueue_script( 'wc-add-to-cart-variation' ); |
| 250 | 256 | if ( version_compare( WC()->version, '3.0.0', '>=' ) ) { |
| 251 | 257 | if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) { |
| 252 | 258 | wp_enqueue_script( 'zoom' ); |
| @@ -301,9 +307,9 @@ | ||
| 301 | 307 | * @return string Filtered HTML. |
| 302 | 308 | */ |
| 303 | 309 | public function add_button_for_block( $item_html, $data, $product ) { |
| 304 | 310 | // Add the link "Add to wishlist" in the loop. |
| 305 | - $shop_btn_position = Fns::get_option( 'modules', 'quick_view', 'loop_btn_position', 'after_add_to_cart' ); | |
| 311 | + $shop_btn_position = Fns::get_option( 'modules', 'quick_view', 'loop_btn_position', 'after_add_to_cart' ); | |
| 306 | 312 | ob_start(); |
| 307 | 313 | $this->print_button( $product->get_id() ); |
| 308 | 314 | $button = ob_get_clean(); |
| 309 | 315 | $parts = []; |