| @@ -85,9 +85,10 @@ | ||
| 85 | 85 | public function container( $content, $settings, $class = '', $template = '', $fullwidth = false, $ajax = true ) { |
| 86 | 86 | $rand = wp_rand(); |
| 87 | 87 | $layout_id = 'rtsb-container-' . $rand; |
| 88 | 88 | $metas = RenderHelpers::meta_dataset( $settings, $template ); |
| 89 | - $layout = $metas['layout']; | |
| 89 | + $raw_layout = esc_html( $metas['layout'] ); | |
| 90 | + $layout = RenderHelpers::filter_layout( $raw_layout, $template ); | |
| 90 | 91 | $style_attr = '--rtsb-default-columns: ' . esc_attr( RenderHelpers::default_columns( $layout ) ); |
| 91 | 92 | $view_mode = $settings['view_mode'] ?? 'grid'; |
| 92 | 93 | $view_mode = isset( $_GET['displayview'] ) ? sanitize_text_field( wp_unslash( $_GET['displayview'] ) ) : $view_mode; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 93 | 94 | $tooltip_attr = 'list' == $view_mode && ! empty( $metas['tooltip_position_list'] ) ? esc_attr( $metas['tooltip_position_list'] ) : $metas['tooltip_position']; |
| @@ -108,9 +109,9 @@ | ||
| 108 | 109 | // Attributes for the container. |
| 109 | 110 | $container_attributes = [ |
| 110 | 111 | 'id' => $layout_id, |
| 111 | 112 | 'class' => $container_classes, |
| 112 | - 'style' => $style_attr, | |
| 113 | + 'style' => apply_filters( 'rtsb/product/container/attr', $style_attr, $settings ), | |
| 113 | 114 | 'data-layout' => $layout, |
| 114 | 115 | 'data-tooltip-position' => $tooltip_attr, |
| 115 | 116 | ]; |
| 116 | 117 | |
| @@ -163,13 +164,15 @@ | ||
| 163 | 164 | * |
| 164 | 165 | * @return string |
| 165 | 166 | */ |
| 166 | 167 | public function row( $content, $settings, $hook_html = '', $raw_settings = [] ) { |
| 167 | - $layout = $settings['layout']; | |
| 168 | + $raw_layout = esc_html( $settings['layout'] ); | |
| 169 | + $layout = RenderHelpers::filter_layout( $raw_layout ); | |
| 170 | + | |
| 168 | 171 | $rand = wp_rand(); |
| 169 | - $is_carousel = preg_match( '/slider/', $layout ); | |
| 172 | + $is_carousel = preg_match( '/slider/', $raw_layout ); | |
| 170 | 173 | |
| 171 | - if ( preg_match( '/category/', $layout ) && ( ! empty( $settings['active_cat_slider'] ) ) ) { | |
| 174 | + if ( preg_match( '/category/', $raw_layout ) && ( ! empty( $settings['active_cat_slider'] ) ) ) { | |
| 172 | 175 | $is_carousel = true; |
| 173 | 176 | } |
| 174 | 177 | |
| 175 | 178 | // Row classes. |
| @@ -237,11 +240,18 @@ | ||
| 237 | 240 | } |
| 238 | 241 | |
| 239 | 242 | $i = 0; |
| 240 | 243 | |
| 241 | - foreach ( $products as $product ) { | |
| 244 | + global $product; | |
| 245 | + $isGlobalProduct = false; | |
| 246 | + if ( $product instanceof WC_Product ) { | |
| 247 | + $isGlobalProduct = $product; | |
| 248 | + } | |
| 249 | + | |
| 250 | + foreach ( $products as $_product ) { | |
| 242 | 251 | $i++; |
| 243 | - $GLOBALS['product'] = $product; | |
| 252 | + $GLOBALS['product'] = $_product; | |
| 253 | + $layout = RenderHelpers::filter_layout( esc_html( $settings['layout'] ), $template ); | |
| 244 | 254 | |
| 245 | 255 | /** |
| 246 | 256 | * Before product template render hook. |
| 247 | 257 | */ |
| @@ -247,12 +257,12 @@ | ||
| 247 | 257 | */ |
| 248 | 258 | do_action( 'rtsb_before_product_template_render' ); |
| 249 | 259 | |
| 250 | 260 | // Loop arg. |
| 251 | - $arg = $this->arg_dataset( $settings, $product, $settings['lazy_load'], $i ); | |
| 261 | + $arg = $this->arg_dataset( $settings, $_product, $settings['lazy_load'], $i ); | |
| 252 | 262 | |
| 253 | 263 | // Get template. |
| 254 | - $html .= Fns::load_template( $template . $settings['layout'], $arg, true ); | |
| 264 | + $html .= Fns::load_template( $template . $layout, $arg, true ); | |
| 255 | 265 | |
| 256 | 266 | /** |
| 257 | 267 | * After product template render hook. |
| 258 | 268 | */ |
| @@ -259,9 +269,11 @@ | ||
| 259 | 269 | do_action( 'rtsb_after_product_template_render' ); |
| 260 | 270 | |
| 261 | 271 | unset( $GLOBALS['product'] ); |
| 262 | 272 | } |
| 263 | - | |
| 273 | + if ( $isGlobalProduct ) { | |
| 274 | + $GLOBALS['product'] = $isGlobalProduct; | |
| 275 | + } | |
| 264 | 276 | return $html; |
| 265 | 277 | } |
| 266 | 278 | |
| 267 | 279 | /** |
| @@ -368,10 +380,16 @@ | ||
| 368 | 380 | do_action( 'rtsb/elements/render/before_query', $settings, $args ); |
| 369 | 381 | |
| 370 | 382 | // Query. |
| 371 | 383 | $product_query = new WC_Product_Query( $args ); |
| 372 | - $products = $pagination ? $product_query->get_products()->products : $product_query->get_products(); | |
| 373 | 384 | |
| 385 | + /** | |
| 386 | + * Product query hook. | |
| 387 | + */ | |
| 388 | + do_action( 'rtsb/elements/render/product_query', $product_query, $this ); | |
| 389 | + | |
| 390 | + $products = $pagination ? $product_query->get_products()->products : $product_query->get_products(); | |
| 391 | + | |
| 374 | 392 | if ( ! empty( $products ) ) { |
| 375 | 393 | // Start rendering. |
| 376 | 394 | $hook_html .= $this->render_start( $metas, $settings, $temp_args ); |
| 377 | 395 | |
| @@ -477,9 +495,9 @@ | ||
| 477 | 495 | // Pagination. |
| 478 | 496 | $this->html .= '<div class="rtsb-archive-pagination-wrap">'; |
| 479 | 497 | |
| 480 | 498 | if ( $pagination ) { |
| 481 | - if ( Fns::product_filters_has_ajax( 'shop' ) || Fns::product_filters_has_ajax( 'archive' ) ) { | |
| 499 | + if ( Fns::product_filters_has_ajax( apply_filters( 'rtsb/builder/set/current/page/type', '' ) ) ) { | |
| 482 | 500 | if ( $wp_query->max_num_pages > 1 ) { |
| 483 | 501 | $this->add_attribute( |
| 484 | 502 | 'rtsb_load_more_btn_attr_' . $rand, |
| 485 | 503 | [ |
| @@ -489,9 +507,9 @@ | ||
| 489 | 507 | ); |
| 490 | 508 | |
| 491 | 509 | $this->html .= |
| 492 | 510 | "<div class='rtsb-load-more rtsb-pos-r'> |
| 493 | - <button '{$this->get_attribute_string( 'rtsb_load_more_btn_attr_' . $rand )}'> | |
| 511 | + <button {$this->get_attribute_string( 'rtsb_load_more_btn_attr_' . $rand )}> | |
| 494 | 512 | <span>" . esc_html__( 'Load More', 'shopbuilder' ) . "</span> |
| 495 | 513 | </button> |
| 496 | 514 | <div class='rtsb-loadmore-loading rtsb-ball-clip-rotate'><div></div></div> |
| 497 | 515 | </div>"; |
| @@ -864,8 +882,9 @@ | ||
| 864 | 882 | $arg['anchor_class'] = null; |
| 865 | 883 | $arg['hover_img_html'] = null; |
| 866 | 884 | $arg['s_link'] = []; |
| 867 | 885 | $arg['add_to_cart'] = ''; |
| 886 | + $arg['p_counter'] = absint( $i ); | |
| 868 | 887 | $arg['p_id'] = $post_id; |
| 869 | 888 | $arg['product'] = $product; |
| 870 | 889 | $arg['p_link'] = $product->get_permalink(); |
| 871 | 890 | $arg['p_sale'] = ''; |
| @@ -919,18 +938,21 @@ | ||
| 919 | 938 | |
| 920 | 939 | $arg['class'] .= ' animated rtFadeIn'; |
| 921 | 940 | |
| 922 | 941 | if ( in_array( 'badges', $meta['visibility'], true ) ) { |
| 923 | - $arg['p_sale'] = Fns::get_promo_badge( | |
| 942 | + $badge_module = ! empty( $meta['enable_badges_module'] ); | |
| 943 | + $arg['p_sale'] = Fns::is_module_active( 'product_badges' ) && $badge_module ? 'rtsb_yes' : Fns::get_promo_badge( | |
| 924 | 944 | $product, |
| 925 | 945 | $meta['sale_badge_type'], |
| 926 | 946 | $meta['sale_badge_text'], |
| 927 | - $meta['out_of_stock_badge_text'] | |
| 947 | + apply_filters( 'rtsb/elementor/render/out_of_stock_badge_text', $meta['out_of_stock_badge_text'] ) | |
| 928 | 948 | ); |
| 929 | 949 | } |
| 930 | 950 | |
| 931 | 951 | $arg['badge_class'] = RenderHelpers::badge_class( $meta['badge_preset'] ); |
| 932 | 952 | |
| 953 | + $meta['add_to_cart_text'] = apply_filters( 'rtsb/elementor/render/add_to_cart_text', $meta['add_to_cart_text'], $product ); | |
| 954 | + | |
| 933 | 955 | if ( ! $meta['show_cart_text'] ) { |
| 934 | 956 | $meta['add_to_cart_text'] = ''; |
| 935 | 957 | $meta['add_to_cart_success_text'] = ''; |
| 936 | 958 | } |
| @@ -956,8 +978,9 @@ | ||
| 956 | 978 | 'text' => $meta['add_to_cart_text'], |
| 957 | 979 | 'success' => $meta['add_to_cart_success_text'], |
| 958 | 980 | 'icon_html' => $cart_icon, |
| 959 | 981 | 'alignment' => $meta['add_to_cart_alignment'], |
| 982 | + 'product' => $product, | |
| 960 | 983 | ] |
| 961 | 984 | ); |
| 962 | 985 | } |
| 963 | 986 | } |
| @@ -1042,9 +1065,10 @@ | ||
| 1042 | 1065 | 'type' => $type, |
| 1043 | 1066 | 'text' => $text, |
| 1044 | 1067 | 'success' => $success, |
| 1045 | 1068 | 'icon_html' => $icon_html, |
| 1046 | - 'alignment' => $alignment | |
| 1069 | + 'alignment' => $alignment, | |
| 1070 | + 'product' => $product | |
| 1047 | 1071 | ) = $args; |
| 1048 | 1072 | |
| 1049 | 1073 | $content = null; |
| 1050 | 1074 | $rand = wp_rand(); |
| @@ -1077,8 +1101,10 @@ | ||
| 1077 | 1101 | |
| 1078 | 1102 | $content .= '<div class="rtsb-wc-add-to-cart-wrap">'; |
| 1079 | 1103 | |
| 1080 | 1104 | if ( 'variable' === $type || 'grouped' === $type ) { |
| 1105 | + $cart_attr = apply_filters( 'rtsb/elementor/render/cart_attributes', $cart_attr, $product ); | |
| 1106 | + | |
| 1081 | 1107 | $this->add_attribute( 'rtsb_add_to_cart_button_' . $id . $rand, $cart_attr ); |
| 1082 | 1108 | |
| 1083 | 1109 | $text_btn = 'grouped' === $type ? __( 'View Products', 'shopbuilder' ) : __( 'Select Options', 'shopbuilder' ); |
| 1084 | 1110 | |
| @@ -1101,8 +1127,9 @@ | ||
| 1101 | 1127 | } else { |
| 1102 | 1128 | $cart_attr['href'] = $cart_attr['href'] . '?add-to-cart=' . absint( $id ); |
| 1103 | 1129 | $cart_attr['class'] .= ' rtsb-add-to-cart-btn'; |
| 1104 | 1130 | $cart_attr['data-type'] = $type; |
| 1131 | + $cart_attr = apply_filters( 'rtsb/elementor/render/cart_attributes', $cart_attr, $product ); | |
| 1105 | 1132 | |
| 1106 | 1133 | $this->add_attribute( 'rtsb_add_to_cart_button_' . $id . $rand, $cart_attr ); |
| 1107 | 1134 | |
| 1108 | 1135 | $content .= '<a ' . $this->get_attribute_string( 'rtsb_add_to_cart_button_' . $id . $rand ) . '>'; |
| @@ -1280,9 +1307,9 @@ | ||
| 1280 | 1307 | * @return void |
| 1281 | 1308 | */ |
| 1282 | 1309 | public function no_products_msg( $metas ) { |
| 1283 | 1310 | $content = |
| 1284 | - '<div class="woocommerce-no-products-found"> | |
| 1311 | + '<div class="rtsb-notice woocommerce-no-products-found"> | |
| 1285 | 1312 | <div class="woocommerce-info">' . esc_html__( 'No products were found matching your selection.', 'shopbuilder' ) . '</div> |
| 1286 | 1313 | </div>'; |
| 1287 | 1314 | |
| 1288 | 1315 | $this->row( $content, $metas ); |