| @@ -71,16 +71,8 @@ | ||
| 71 | 71 | * @var string |
| 72 | 72 | */ |
| 73 | 73 | public static $tags_product_page_template = 'rtsb_tags_product_page_template'; |
| 74 | 74 | /** |
| 75 | - * Term-meta key used on `product_brand` terms to point at the | |
| 76 | - * Product-Page template that targets that brand. Mirrors | |
| 77 | - * $categories_product_page_template / $tags_product_page_template. | |
| 78 | - * | |
| 79 | - * @var string | |
| 80 | - */ | |
| 81 | - public static $brands_product_page_template = 'rtsb_brands_product_page_template'; | |
| 82 | - /** | |
| 83 | 75 | * Get template ID based on page type. |
| 84 | 76 | * |
| 85 | 77 | * @param string $type Page type (product, archive, etc.). |
| 86 | 78 | * @return int Template ID or 0. |
| @@ -108,9 +100,9 @@ | ||
| 108 | 100 | } |
| 109 | 101 | |
| 110 | 102 | switch ( $type ) { |
| 111 | 103 | case 'product': |
| 112 | - if ( ! $post instanceof \WP_Post || 'product' !== $post->post_type ) { | |
| 104 | + if ( 'product' !== $post->post_type ) { | |
| 113 | 105 | break; |
| 114 | 106 | } |
| 115 | 107 | $cache_key_product = 'template_for_product_page_' . get_the_ID(); |
| 116 | 108 | $template = get_transient( $cache_key_product ); |
| @@ -117,8 +109,9 @@ | ||
| 117 | 109 | if ( $template && 'publish' === get_post_status( $template ) ) { |
| 118 | 110 | $post_id = $template; |
| 119 | 111 | break; |
| 120 | 112 | } |
| 113 | + Cache::set_transient_cache_key( $cache_key_product ); | |
| 121 | 114 | $builder_id = get_post_meta( get_the_ID(), self::$view_template_for_products_meta, true ); |
| 122 | 115 | |
| 123 | 116 | if ( self::get_specific_product_as_default( $builder_id ) && 'publish' === get_post_status( $builder_id ) ) { |
| 124 | 117 | $post_id = $builder_id; |
| @@ -140,25 +133,8 @@ | ||
| 140 | 133 | break 2; |
| 141 | 134 | } |
| 142 | 135 | } |
| 143 | 136 | } |
| 144 | - // Brand check (between Category and Tag). Requires the `product_brand` | |
| 145 | - // taxonomy (WooCommerce 9.4+ native, or a brand plugin that registers it). | |
| 146 | - $brands = taxonomy_exists( 'product_brand' ) ? get_the_terms( get_the_ID(), 'product_brand' ) : false; | |
| 147 | - if ( ! is_wp_error( $brands ) && ! empty( $brands ) ) { | |
| 148 | - foreach ( $brands as $brand_term ) { | |
| 149 | - $template_id = get_term_meta( $brand_term->term_id, self::$brands_product_page_template, true ); | |
| 150 | - if ( empty( $template_id ) || 'publish' !== get_post_status( $template_id ) ) { | |
| 151 | - continue; | |
| 152 | - } | |
| 153 | - $set_default_option_name = self::option_name_product_page_specific_brand_set_default( $template_id ); | |
| 154 | - if ( TemplateSettings::instance()->get_option( $set_default_option_name ) ) { | |
| 155 | - $post_id = $template_id; | |
| 156 | - set_transient( $cache_key_product, $post_id, 12 * HOUR_IN_SECONDS ); // Cache duration: 12 hours. | |
| 157 | - break 2; | |
| 158 | - } | |
| 159 | - } | |
| 160 | - } | |
| 161 | 137 | $tags = get_the_terms( get_the_ID(), 'product_tag' ); |
| 162 | 138 | if ( ! is_wp_error( $tags ) && ! empty( $tags ) ) { |
| 163 | 139 | foreach ( $tags as $term ) { |
| 164 | 140 | $template_id = get_term_meta( $term->term_id, self::$tags_product_page_template, true ); |
| @@ -183,8 +159,9 @@ | ||
| 183 | 159 | if ( $template && 'publish' === get_post_status( $template ) ) { |
| 184 | 160 | $post_id = $template; |
| 185 | 161 | break; |
| 186 | 162 | } |
| 163 | + Cache::set_transient_cache_key( $cache_key_archive ); | |
| 187 | 164 | $builder_id = get_term_meta( $queried_object->term_id, self::$view_template_for_archive_meta, true ); |
| 188 | 165 | if ( self::get_specific_category_as_default( $builder_id ) && 'publish' === get_post_status( $builder_id ) ) { |
| 189 | 166 | $post_id = $builder_id; |
| 190 | 167 | set_transient( $cache_key_archive, $post_id, 12 * HOUR_IN_SECONDS ); // Cache duration: 12 hours. |
| @@ -192,10 +169,8 @@ | ||
| 192 | 169 | } |
| 193 | 170 | break; |
| 194 | 171 | |
| 195 | 172 | default: |
| 196 | - $post_id = (int) apply_filters( 'rtsb/builder/page/id/by/type/resolve', $post_id, $type ); | |
| 197 | - break; | |
| 198 | 173 | } |
| 199 | 174 | if ( 'publish' === get_post_status( $post_id ) && self::builder_type( $post_id ) === $type ) { |
| 200 | 175 | self::$cache[ $cache_key ] = $post_id; |
| 201 | 176 | return $post_id; |
| @@ -200,26 +175,8 @@ | ||
| 200 | 175 | self::$cache[ $cache_key ] = $post_id; |
| 201 | 176 | return $post_id; |
| 202 | 177 | } |
| 203 | 178 | |
| 204 | - // Fallback: use shop template for archive pages when no archive template exists. | |
| 205 | - // Filterable so other archive-like types (e.g. brand / tag archives) can opt in. | |
| 206 | - $fallback_to_shop = apply_filters( 'rtsb/builder/archive/fallback_to_shop', 'archive' === $type, $type ); | |
| 207 | - if ( $fallback_to_shop ) { | |
| 208 | - $shop_options = self::option_name( 'shop' ); | |
| 209 | - $shop_post_id = TemplateSettings::instance()->get_option( $shop_options ); | |
| 210 | - | |
| 211 | - if ( empty( $shop_post_id ) ) { | |
| 212 | - $shop_options = self::option_name( 'shop', true ); | |
| 213 | - $shop_post_id = TemplateSettings::instance()->get_option( $shop_options ); | |
| 214 | - } | |
| 215 | - | |
| 216 | - if ( $shop_post_id && 'publish' === get_post_status( $shop_post_id ) && 'shop' === self::builder_type( $shop_post_id ) ) { | |
| 217 | - self::$cache[ $cache_key ] = $shop_post_id; | |
| 218 | - return $shop_post_id; | |
| 219 | - } | |
| 220 | - } | |
| 221 | - | |
| 222 | 179 | return 0; |
| 223 | 180 | } |
| 224 | 181 | |
| 225 | 182 | /** |
| @@ -243,9 +200,9 @@ | ||
| 243 | 200 | * @return array |
| 244 | 201 | */ |
| 245 | 202 | public static function builder_page_types() { |
| 246 | 203 | $page_types = [ |
| 247 | - 'shop' => 'Shop/Archive', | |
| 204 | + 'shop' => 'Shop', | |
| 248 | 205 | 'archive' => 'Category Archive', |
| 249 | 206 | 'product' => 'Product Page', |
| 250 | 207 | 'cart' => 'Cart', |
| 251 | 208 | 'checkout' => 'Checkout', |
| @@ -410,37 +367,8 @@ | ||
| 410 | 367 | |
| 411 | 368 | return 'rtsb_template_product_page_specific_tag_set_default_' . $post_id; |
| 412 | 369 | } |
| 413 | 370 | /** |
| 414 | - * Get option name for the selected product brand template. | |
| 415 | - * | |
| 416 | - * @param int|string $template_id Template ID for the brand. | |
| 417 | - * | |
| 418 | - * @return string Generated option name. | |
| 419 | - */ | |
| 420 | - public static function option_name_product_page_selected_brand( $template_id ) { | |
| 421 | - $_suff = null; | |
| 422 | - if ( $template_id ) { | |
| 423 | - $_suff = '_' . $template_id; | |
| 424 | - } | |
| 425 | - | |
| 426 | - return self::$brands_product_page_template . $_suff; | |
| 427 | - } | |
| 428 | - /** | |
| 429 | - * Get option name for setting a specific product brand template as default. | |
| 430 | - * | |
| 431 | - * @param int|string $post_id Template or post ID. | |
| 432 | - * | |
| 433 | - * @return string|null Option name or null if post ID is not provided. | |
| 434 | - */ | |
| 435 | - public static function option_name_product_page_specific_brand_set_default( $post_id ) { | |
| 436 | - if ( ! $post_id ) { | |
| 437 | - return; | |
| 438 | - } | |
| 439 | - | |
| 440 | - return 'rtsb_template_product_page_specific_brand_set_default_' . $post_id; | |
| 441 | - } | |
| 442 | - /** | |
| 443 | 371 | * Get option name for the selected archive (category) template. |
| 444 | 372 | * |
| 445 | 373 | * @param int|string $template_id Template ID. |
| 446 | 374 | * |
| @@ -584,14 +512,8 @@ | ||
| 584 | 512 | $builder_type = self::builder_type( $builder_id ); |
| 585 | 513 | if ( $type === $builder_type && $is_page ) { |
| 586 | 514 | return true; |
| 587 | 515 | } |
| 588 | - | |
| 589 | - // Allow shop template as fallback for archive pages. | |
| 590 | - if ( 'archive' === $type && 'shop' === $builder_type && $is_page ) { | |
| 591 | - return true; | |
| 592 | - } | |
| 593 | - | |
| 594 | 516 | return false; |
| 595 | 517 | } |
| 596 | 518 | |
| 597 | 519 | /** |
| @@ -603,22 +525,7 @@ | ||
| 603 | 525 | * @return mixed |
| 604 | 526 | */ |
| 605 | 527 | public static function get_builder_content( $template_id, $with_css = false ) { |
| 606 | 528 | // Don't Use cache: tickets ID -> 75376. |
| 607 | - if ( ! defined( 'ELEMENTOR_VERSION' ) || ! class_exists( '\Elementor\Plugin' ) ) { | |
| 608 | - return ''; | |
| 609 | - } | |
| 610 | - | |
| 611 | - try { | |
| 612 | - $plugin = \Elementor\Plugin::instance(); | |
| 613 | - | |
| 614 | - if ( ! $plugin || ! isset( $plugin->frontend ) ) { | |
| 615 | - return ''; | |
| 616 | - } | |
| 617 | - | |
| 618 | - return $plugin->frontend->get_builder_content_for_display( $template_id, $with_css ); | |
| 619 | - } catch ( \Throwable $e ) { | |
| 620 | - error_log( 'ShopBuilder content render error: ' . $e->getMessage() ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log | |
| 621 | - return ''; | |
| 622 | - } | |
| 529 | + return \Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $template_id, $with_css ); | |
| 623 | 530 | } |
| 624 | 531 | } |