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