| @@ -1,5 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * Quick View Module Class. | |
| 4 | + * | |
| 5 | + * @package RadiusTheme\SB | |
| 6 | + */ | |
| 2 | 7 | |
| 3 | 8 | namespace RadiusTheme\SB\Modules\QuickView; |
| 4 | 9 | |
| 5 | 10 | use RadiusTheme\SB\Helpers\Fns; |
| @@ -10,21 +15,32 @@ | ||
| 10 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | 16 | exit( 'This script cannot be accessed directly.' ); |
| 12 | 17 | } |
| 13 | 18 | |
| 19 | +/** | |
| 20 | + * Quick View Module Class. | |
| 21 | + */ | |
| 14 | 22 | class QuickViewFrontEnd { |
| 15 | 23 | use SingletonTrait; |
| 16 | 24 | |
| 25 | + /** | |
| 26 | + * Asset Handle | |
| 27 | + * | |
| 28 | + * @var string | |
| 29 | + */ | |
| 30 | + private $handle = 'rtsb-quick-view'; | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * Class constructor. | |
| 34 | + */ | |
| 17 | 35 | public function __construct() { |
| 18 | - add_action( 'wp_enqueue_scripts', [ $this, 'enqueue' ] ); | |
| 36 | + add_action( 'wp_enqueue_scripts', [ $this, 'enqueue' ], 99 ); | |
| 19 | 37 | |
| 20 | 38 | // Gallery Plugin Support rtwpvg_disable_enqueue_scripts. |
| 21 | 39 | add_filter( 'rtwpvg_disable_enqueue_scripts', '__return_false', 11 ); |
| 22 | 40 | |
| 23 | 41 | // Template. |
| 24 | - | |
| 25 | 42 | 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 | 43 | |
| 28 | 44 | add_action( 'rtsb/modules/quick_view/print_button', [ $this, 'print_button' ] ); |
| 29 | 45 | |
| 30 | 46 | // Load action for product template. |
| @@ -49,9 +65,9 @@ | ||
| 49 | 65 | * @return void |
| 50 | 66 | * @since 1.0.0 |
| 51 | 67 | */ |
| 52 | 68 | public function quick_view_action_template() { |
| 53 | - | |
| 69 | + wp_enqueue_style( 'elementor-frontend' ); | |
| 54 | 70 | // Image. |
| 55 | 71 | add_action( 'rtsb/wcqv/product/image', 'woocommerce_show_product_sale_flash', 10 ); |
| 56 | 72 | add_action( 'rtsb/wcqv/product/image', 'woocommerce_show_product_images', 20 ); |
| 57 | 73 | |
| @@ -63,8 +79,13 @@ | ||
| 63 | 79 | add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_add_to_cart', 25 ); |
| 64 | 80 | add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_meta', 30 ); |
| 65 | 81 | } |
| 66 | 82 | |
| 83 | + /** | |
| 84 | + * Quick View AJAX. | |
| 85 | + * | |
| 86 | + * @return void | |
| 87 | + */ | |
| 67 | 88 | public function product_quick_view_ajax() { |
| 68 | 89 | $product_id = isset( $_REQUEST['product_id'] ) ? absint( $_REQUEST['product_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 69 | 90 | |
| 70 | 91 | if ( empty( $product_id ) || 'publish' !== get_post_status( $product_id ) ) { |
| @@ -84,12 +105,8 @@ | ||
| 84 | 105 | // Remove product thumbnails gallery. |
| 85 | 106 | if ( defined( 'RTWPVG_VERSION' ) ) { |
| 86 | 107 | remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 ); |
| 87 | 108 | } |
| 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 ); | |
| 91 | - } | |
| 92 | 109 | |
| 93 | 110 | ob_start(); |
| 94 | 111 | Fns::load_template( 'quick-view/content' ); |
| 95 | 112 | $html = ob_get_contents(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| @@ -104,9 +121,8 @@ | ||
| 104 | 121 | * @return void |
| 105 | 122 | * @since 1.0.0 |
| 106 | 123 | */ |
| 107 | 124 | public function attach_button() { |
| 108 | - | |
| 109 | 125 | $positions = apply_filters( |
| 110 | 126 | 'rtsb/module/quick_view/loop_btn_position', |
| 111 | 127 | [ |
| 112 | 128 | |
| @@ -125,9 +141,8 @@ | ||
| 125 | 141 | ] |
| 126 | 142 | ); |
| 127 | 143 | |
| 128 | 144 | // Add the link "Add to wishlist" in the loop. |
| 129 | - | |
| 130 | 145 | $loop_btn_position = Fns::get_option( 'modules', 'quick_view', 'loop_btn_position', 'after_add_to_cart' ); |
| 131 | 146 | |
| 132 | 147 | if ( 'shortcode' !== $loop_btn_position && isset( $positions[ $loop_btn_position ]['hook'] ) ) { |
| 133 | 148 | add_action( |
| @@ -138,9 +153,9 @@ | ||
| 138 | 153 | ], |
| 139 | 154 | isset( $positions[ $loop_btn_position ]['priority'] ) ? $positions[ $loop_btn_position ]['priority'] : '' |
| 140 | 155 | ); |
| 141 | 156 | } |
| 142 | - // TODO:: Maybe this hooks is not working. Need to Check gutenberg compatibility. | |
| 157 | + | |
| 143 | 158 | // Add the link "Quick view" for Gutenberg blocks. |
| 144 | 159 | add_filter( 'woocommerce_blocks_product_grid_item_html', [ $this, 'add_button_for_block' ], 10, 3 ); |
| 145 | 160 | } |
| 146 | 161 | |
| @@ -148,30 +163,8 @@ | ||
| 148 | 163 | * Print "Add to compare" button |
| 149 | 164 | * |
| 150 | 165 | * @return void |
| 151 | 166 | */ |
| 152 | - public function woocommerce_product_thumbnails_before() { | |
| 153 | - ?> | |
| 154 | - <div class="rtsb-gallery-images-wrapper"> | |
| 155 | - <?php | |
| 156 | - } | |
| 157 | - /** | |
| 158 | - * Print "Add to compare" button | |
| 159 | - * | |
| 160 | - * @return void | |
| 161 | - */ | |
| 162 | - public function woocommerce_product_thumbnails_after() { | |
| 163 | - | |
| 164 | - ?> | |
| 165 | - </div> | |
| 166 | - <?php | |
| 167 | - } | |
| 168 | - | |
| 169 | - /** | |
| 170 | - * Print "Add to compare" button | |
| 171 | - * | |
| 172 | - * @return void | |
| 173 | - */ | |
| 174 | 167 | public function button_hook() { |
| 175 | 168 | if ( ! apply_filters( 'rtsb/module/quick_view/show_button', true ) ) { |
| 176 | 169 | return; |
| 177 | 170 | } |
| @@ -178,14 +171,17 @@ | ||
| 178 | 171 | global $product; |
| 179 | 172 | if ( $product instanceof WC_Product ) { |
| 180 | 173 | do_action( 'rtsb/modules/quick_view/print_button', $product->get_id() ); |
| 181 | 174 | } |
| 182 | - | |
| 183 | 175 | } |
| 184 | 176 | |
| 185 | 177 | |
| 186 | 178 | /** |
| 187 | - * @return string|void | |
| 179 | + * Print "Add to compare" button. | |
| 180 | + * | |
| 181 | + * @param int $product_id Product ID. | |
| 182 | + * | |
| 183 | + * @return void | |
| 188 | 184 | */ |
| 189 | 185 | public function print_button( $product_id = 0 ) { |
| 190 | 186 | global $product; |
| 191 | 187 | |
| @@ -192,13 +188,9 @@ | ||
| 192 | 188 | if ( ! $product instanceof WC_Product && $product_id ) { |
| 193 | 189 | $product = wc_get_product( $product_id ); |
| 194 | 190 | } |
| 195 | 191 | |
| 196 | - // if ( ! $current_product instanceof WC_Product ) { | |
| 197 | - // return ''; | |
| 198 | - // } | |
| 199 | - | |
| 200 | - $classes = []; // button class. | |
| 192 | + $classes = []; | |
| 201 | 193 | $button_text = Fns::get_option( 'modules', 'quick_view', 'button_text', esc_html__( 'Quick View', 'shopbuilder' ) ); |
| 202 | 194 | |
| 203 | 195 | $icon_html = '<i class="rtsb-icon rtsb-icon-eye"></i>'; |
| 204 | 196 | // get product type. |
| @@ -203,14 +195,15 @@ | ||
| 203 | 195 | $icon_html = '<i class="rtsb-icon rtsb-icon-eye"></i>'; |
| 204 | 196 | // get product type. |
| 205 | 197 | $product_type = $product->get_type(); |
| 206 | 198 | $params = [ |
| 207 | - 'classes' => $classes, | |
| 208 | - 'product_id' => $product->get_id(), | |
| 209 | - 'product_type' => $product_type, | |
| 210 | - 'button_text' => $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', '' ), | |
| 199 | + 'classes' => $classes, | |
| 200 | + 'product_id' => $product->get_id(), | |
| 201 | + 'product_type' => $product_type, | |
| 202 | + 'button_text' => $button_text, | |
| 203 | + 'has_button_text' => ! empty( Fns::get_option( 'modules', 'quick_view', 'button_text', '' ) ), | |
| 204 | + 'left_text' => apply_filters( 'rtsb/module/quick_view/button_left_text', '' ), | |
| 205 | + 'right_text' => apply_filters( 'rtsb/module/quick_view/button_right_text', '' ), | |
| 213 | 206 | ]; |
| 214 | 207 | // let third party developer filter options. |
| 215 | 208 | $atts = apply_filters( 'rtsb/module/quick_view/button_params', $params ); |
| 216 | 209 | // set fragment options. |
| @@ -218,49 +211,51 @@ | ||
| 218 | 211 | |
| 219 | 212 | Fns::load_template( 'quick-view/button', $atts ); |
| 220 | 213 | } |
| 221 | 214 | |
| 222 | - | |
| 223 | 215 | /** |
| 224 | 216 | * Wishlist button Shortcode callable function |
| 225 | 217 | * |
| 226 | - * @param array $atts | |
| 227 | - * @param string $content | |
| 228 | - * | |
| 229 | - * @return string [HTML] | |
| 218 | + * @return string | |
| 230 | 219 | */ |
| 231 | - public function button_shortcode( $atts, $content = '' ) { | |
| 220 | + public function button_shortcode() { | |
| 232 | 221 | global $product; |
| 222 | + | |
| 233 | 223 | if ( ! $product instanceof WC_Product ) { |
| 234 | 224 | return ''; |
| 235 | 225 | } |
| 226 | + | |
| 236 | 227 | ob_start(); |
| 237 | - | |
| 238 | 228 | do_action( 'rtsb/modules/quick_view/print_button', $product->get_id() ); |
| 239 | 229 | |
| 240 | 230 | return ob_get_clean(); |
| 241 | 231 | } |
| 242 | 232 | |
| 233 | + /** | |
| 234 | + * Enqueue assets. | |
| 235 | + * | |
| 236 | + * @return void | |
| 237 | + */ | |
| 243 | 238 | public function enqueue() { |
| 239 | + wp_enqueue_style( 'elementor-icons-fa-regular' ); | |
| 240 | + wp_enqueue_style( 'elementor-icons-fa-solid' ); | |
| 241 | + wp_enqueue_style( 'elementor-icons-shared-0' ); | |
| 244 | 242 | |
| 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' ); | |
| 243 | + if ( ! class_exists( 'WooProductVariationGallery' ) && current_theme_supports( 'wc-product-gallery-slider' ) ) { | |
| 244 | + wp_enqueue_script( 'wc-flexslider' ); | |
| 253 | 245 | } |
| 254 | 246 | |
| 255 | 247 | wp_enqueue_script( 'wc-add-to-cart-variation' ); |
| 248 | + | |
| 256 | 249 | if ( version_compare( WC()->version, '3.0.0', '>=' ) ) { |
| 257 | 250 | if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) { |
| 258 | - wp_enqueue_script( 'zoom' ); | |
| 251 | + wp_enqueue_script( 'wc-zoom' ); | |
| 259 | 252 | } |
| 253 | + | |
| 260 | 254 | if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) { |
| 261 | - wp_enqueue_script( 'photoswipe-ui-default' ); | |
| 255 | + wp_enqueue_script( 'wc-photoswipe-ui-default' ); | |
| 262 | 256 | wp_enqueue_style( 'photoswipe-default-skin' ); |
| 257 | + | |
| 263 | 258 | if ( has_action( 'wp_footer', 'woocommerce_photoswipe' ) === false ) { |
| 264 | 259 | add_action( 'wp_footer', 'woocommerce_photoswipe', 15 ); |
| 265 | 260 | } |
| 266 | 261 | } |
| @@ -265,23 +260,10 @@ | ||
| 265 | 260 | } |
| 266 | 261 | } |
| 267 | 262 | wp_enqueue_script( 'wc-single-product' ); |
| 268 | 263 | } |
| 269 | - | |
| 270 | - wp_register_style( 'rtsb-modules', rtsb()->get_assets_uri( 'modules/modules.css' ), [], RTSB_VERSION ); | |
| 271 | - wp_register_script( | |
| 272 | - 'rtsb-quick-view', | |
| 273 | - rtsb()->get_assets_uri( 'modules/quick-view.js' ), | |
| 274 | - [ | |
| 275 | - 'jquery', | |
| 276 | - 'rtsb-public', | |
| 277 | - ], | |
| 278 | - RTSB_VERSION, | |
| 279 | - true | |
| 280 | - ); | |
| 281 | - wp_enqueue_style( 'rtsb-modules' ); | |
| 282 | - wp_enqueue_script( 'rtsb-quick-view' ); | |
| 283 | - | |
| 264 | + // Enqueue assets. | |
| 265 | + $this->handle = Fns::enqueue_module_assets( $this->handle, 'quick-view' ); | |
| 284 | 266 | // Allow user to load custom style and scripts! |
| 285 | 267 | do_action( 'rtsb/modules/quick_view/custom_scripts' ); |
| 286 | 268 | |
| 287 | 269 | $params = apply_filters( |
| @@ -292,9 +274,9 @@ | ||
| 292 | 274 | 'isLoggedIn' => is_user_logged_in(), |
| 293 | 275 | ] |
| 294 | 276 | ); |
| 295 | 277 | |
| 296 | - wp_localize_script( 'rtsb-quick-view', 'rtsbQvParams', $params ); | |
| 278 | + wp_localize_script( $this->handle, 'rtsbQvParams', $params ); | |
| 297 | 279 | } |
| 298 | 280 | |
| 299 | 281 | |
| 300 | 282 | /** |