| @@ -54,8 +54,9 @@ | ||
| 54 | 54 | */ |
| 55 | 55 | private function __construct() { |
| 56 | 56 | $this->builder_page_id = BuilderFns::builder_page_id_by_page(); |
| 57 | 57 | $this->page_edit_with = Fns::page_edit_with( $this->builder_page_id ); |
| 58 | + | |
| 58 | 59 | if ( ! is_admin() ) { |
| 59 | 60 | BuilderHooks::instance(); |
| 60 | 61 | } |
| 61 | 62 | |
| @@ -187,24 +188,45 @@ | ||
| 187 | 188 | continue; |
| 188 | 189 | } |
| 189 | 190 | |
| 190 | 191 | if ( ! empty( $element['category'] ) ) { |
| 191 | - try { | |
| 192 | - $widget = false; | |
| 193 | - $import = apply_filters( 'rtsb_import_status', false ); | |
| 194 | - | |
| 195 | - if ( $this->should_register_widget( $element['category'], $import ) ) { | |
| 192 | + $widget = false; | |
| 193 | + $import = apply_filters( 'rtsb_import_status', false ); | |
| 194 | + switch ( $element['category'] ) { | |
| 195 | + case 'product': | |
| 196 | + if ( BuilderFns::is_product() || $import ) { | |
| 197 | + $widget = new $element['base_class'](); | |
| 198 | + } | |
| 199 | + break; | |
| 200 | + case 'shop': | |
| 201 | + if ( BuilderFns::is_archive() || BuilderFns::is_shop() || $import ) { | |
| 202 | + $widget = new $element['base_class'](); | |
| 203 | + } | |
| 204 | + break; | |
| 205 | + case 'archive': | |
| 206 | + if ( BuilderFns::is_archive() || $import ) { | |
| 207 | + $widget = new $element['base_class'](); | |
| 208 | + } | |
| 209 | + break; | |
| 210 | + case 'cart': | |
| 211 | + if ( BuilderFns::is_cart() || $import ) { | |
| 212 | + $widget = new $element['base_class'](); | |
| 213 | + } | |
| 214 | + break; | |
| 215 | + case 'checkout': | |
| 216 | + if ( BuilderFns::is_checkout() || $import ) { | |
| 217 | + $widget = new $element['base_class'](); | |
| 218 | + } | |
| 219 | + break; | |
| 220 | + case 'general': | |
| 196 | 221 | $widget = new $element['base_class'](); |
| 197 | - } | |
| 222 | + break; | |
| 223 | + default: | |
| 224 | + } | |
| 225 | + $widget = apply_filters( 'rtsb/element/list/init/widgets', $widget, $element ); | |
| 198 | 226 | |
| 199 | - $widget = apply_filters( 'rtsb/element/list/init/widgets', $widget, $element ); | |
| 200 | - | |
| 201 | - if ( $widget && is_object( $widget ) ) { | |
| 202 | - $widgets_manager->register( $widget ); | |
| 203 | - } | |
| 204 | - } catch ( \Throwable $e ) { | |
| 205 | - error_log( 'ShopBuilder widget error (' . $element['base_class'] . '): ' . $e->getMessage() ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log | |
| 206 | - continue; | |
| 227 | + if ( $widget && is_object( $widget ) ) { | |
| 228 | + $widgets_manager->register( $widget ); | |
| 207 | 229 | } |
| 208 | 230 | } |
| 209 | 231 | } |
| 210 | 232 | } |
| @@ -209,36 +231,8 @@ | ||
| 209 | 231 | } |
| 210 | 232 | } |
| 211 | 233 | |
| 212 | 234 | /** |
| 213 | - * Determine whether a widget for the given category should be registered | |
| 214 | - * in the current request context. | |
| 215 | - * | |
| 216 | - * @param string $category Element category. | |
| 217 | - * @param bool $import Whether an import is in progress. | |
| 218 | - * | |
| 219 | - * @return bool | |
| 220 | - */ | |
| 221 | - protected function should_register_widget( $category, $import ) { | |
| 222 | - switch ( $category ) { | |
| 223 | - case 'product': | |
| 224 | - return BuilderFns::is_product() || $import; | |
| 225 | - case 'shop': | |
| 226 | - return BuilderFns::is_archive() || BuilderFns::is_shop() || $import; | |
| 227 | - case 'archive': | |
| 228 | - return BuilderFns::is_archive() || $import; | |
| 229 | - case 'cart': | |
| 230 | - return BuilderFns::is_cart() || $import; | |
| 231 | - case 'checkout': | |
| 232 | - return BuilderFns::is_checkout() || $import; | |
| 233 | - case 'general': | |
| 234 | - return true; | |
| 235 | - default: | |
| 236 | - return false; | |
| 237 | - } | |
| 238 | - } | |
| 239 | - | |
| 240 | - /** | |
| 241 | 235 | * Adding custom icons in Elementor |
| 242 | 236 | * |
| 243 | 237 | * @param array $tabs Tabs. |
| 244 | 238 | * |
| @@ -309,20 +303,12 @@ | ||
| 309 | 303 | |
| 310 | 304 | $parent_class = apply_filters( 'rtsb/builder/content/parent_class', [] ); |
| 311 | 305 | |
| 312 | 306 | if ( BuilderFns::is_product() ) { |
| 313 | - $product_id = Fns::get_prepared_product_id(); | |
| 314 | - | |
| 315 | - // Ensure the WordPress global $product is a valid WC_Product before | |
| 316 | - // wc_get_product_class() fires the `woocommerce_post_class` filter. | |
| 317 | - // Some themes (e.g. Blocksy) read the global $product directly inside | |
| 318 | - // that filter and call methods like get_type() on it, which throws a | |
| 319 | - // fatal error when the global is still an unresolved string. | |
| 320 | - $_product = Fns::get_product(); | |
| 321 | - | |
| 307 | + $product_id = Fns::get_prepared_product_id(); | |
| 322 | 308 | $parent_class = wc_get_product_class( $parent_class, $product_id ); |
| 323 | - | |
| 324 | - if ( function_exists( 'rtwpvs' ) && $_product instanceof \WC_Product ) { | |
| 309 | + if ( function_exists( 'rtwpvs' ) ) { | |
| 310 | + $_product = Fns::get_product(); | |
| 325 | 311 | if ( $_product->is_type( 'variable' ) ) { |
| 326 | 312 | $parent_class[] = 'rtwpvs-product'; |
| 327 | 313 | $beside_label = function_exists( 'rtwpvsp' ) && rtwpvs()->get_option( 'attribute_on_click_behavior' ); |
| 328 | 314 | if ( $beside_label ) { |
| @@ -351,29 +337,8 @@ | ||
| 351 | 337 | if ( BuilderFns::is_checkout() ) { |
| 352 | 338 | if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) { |
| 353 | 339 | return; |
| 354 | 340 | } |
| 355 | - | |
| 356 | - $checkout = WC()->checkout(); | |
| 357 | - | |
| 358 | - // Temporarily remove callbacks that Elementor checkout | |
| 359 | - // handles via separate widgets to prevent duplicates. | |
| 360 | - remove_action( 'woocommerce_before_checkout_form', [ Hooks\ActionHooks::class, 'woocommerce_checkout_login_form' ], 10 ); | |
| 361 | - remove_action( 'woocommerce_before_checkout_form', [ Hooks\ActionHooks::class, 'woocommerce_checkout_coupon_form' ], 10 ); | |
| 362 | - remove_action( 'woocommerce_before_checkout_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); | |
| 363 | - | |
| 364 | - do_action( 'woocommerce_before_checkout_form', $checkout ); | |
| 365 | - | |
| 366 | - // Restore callbacks for non-Elementor contexts. | |
| 367 | - add_action( 'woocommerce_before_checkout_form', [ Hooks\ActionHooks::class, 'woocommerce_checkout_login_form' ], 10 ); | |
| 368 | - add_action( 'woocommerce_before_checkout_form', [ Hooks\ActionHooks::class, 'woocommerce_checkout_coupon_form' ], 10 ); | |
| 369 | - add_action( 'woocommerce_before_checkout_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); | |
| 370 | - | |
| 371 | - // If checkout registration is disabled and not logged in, the user cannot checkout. | |
| 372 | - if ( ! $checkout->is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in() ) { | |
| 373 | - echo esc_html( apply_filters( 'woocommerce_checkout_must_be_logged_in_message', __( 'You must be logged in to checkout.', 'shopbuilder' ) ) ); | |
| 374 | - return; | |
| 375 | - } | |
| 376 | 341 | ?> |
| 377 | 342 | <!-- |
| 378 | 343 | woocommerce-checkout added for fix issue with payment method ( Revolut Pay ) |
| 379 | 344 | --> |
| @@ -405,9 +370,8 @@ | ||
| 405 | 370 | } |
| 406 | 371 | ?> |
| 407 | 372 | </form> |
| 408 | 373 | <?php |
| 409 | - do_action( 'woocommerce_after_checkout_form', WC()->checkout() ); | |
| 410 | 374 | } |
| 411 | 375 | ?> |
| 412 | 376 | </div> |
| 413 | 377 | <!-- After Content end --> |
| @@ -445,9 +409,9 @@ | ||
| 445 | 409 | $args = [ |
| 446 | 410 | 'hide_empty' => false, |
| 447 | 411 | 'orderby' => 'name', |
| 448 | 412 | 'order' => 'ASC', |
| 449 | - 'name__like' => $search, | |
| 413 | + 'search' => $search, | |
| 450 | 414 | 'number' => '5', |
| 451 | 415 | ]; |
| 452 | 416 | |
| 453 | 417 | if ( 'all' !== $post_type ) { |