| @@ -1,6 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace EverCompare\Frontend; |
| 3 | + | |
| 4 | +defined( 'ABSPATH' ) || exit; | |
| 3 | 5 | /** |
| 4 | 6 | * Shortcode handler class |
| 5 | 7 | */ |
| 6 | 8 | class Shortcode { |
| @@ -89,12 +91,8 @@ | ||
| 89 | 91 | } else { |
| 90 | 92 | $button_added_text = '<span class="evercompare-btn-text">'.$button_remove_text.'</span>'; |
| 91 | 93 | } |
| 92 | 94 | |
| 93 | - if(\EverCompare\Frontend\Manage_Compare::instance()->is_product_in_compare( $product_id )) { | |
| 94 | - $button_class[] = 'added'; | |
| 95 | - } | |
| 96 | - | |
| 97 | 95 | // Shortcode atts |
| 98 | 96 | $default_atts = array( |
| 99 | 97 | 'product_id' => $product_id, |
| 100 | 98 | 'product_title' => $product_title, |
| @@ -116,34 +114,40 @@ | ||
| 116 | 114 | * @param string $content |
| 117 | 115 | * @return [HTML] |
| 118 | 116 | */ |
| 119 | 117 | public function table_shortcode( $atts, $content = '' ){ |
| 120 | - | |
| 118 | + | |
| 121 | 119 | wp_enqueue_style( 'evercompare-frontend' ); |
| 122 | 120 | wp_enqueue_script( 'evercompare-frontend' ); |
| 123 | 121 | |
| 124 | - /* Fetch From option data */ | |
| 125 | - $empty_compare_text = ever_compare_get_option('empty_table_text','ever_compare_table_settings_tabs'); | |
| 126 | - $return_shop_button = ever_compare_get_option('shop_button_text','ever_compare_table_settings_tabs','Return to shop'); | |
| 122 | + // Shareable link via query param — render server-side (not cached due to query param) | |
| 123 | + if ( ! empty( $_GET['evcompare'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 124 | + /* Fetch From option data */ | |
| 125 | + $empty_compare_text = ever_compare_get_option('empty_table_text','ever_compare_table_settings_tabs'); | |
| 126 | + $return_shop_button = ever_compare_get_option('shop_button_text','ever_compare_table_settings_tabs','Return to shop'); | |
| 127 | 127 | |
| 128 | - /* Product and Field */ | |
| 129 | - $products = Manage_Compare::instance()->get_compared_products_data(); | |
| 130 | - $fields = Manage_Compare::instance()->get_compare_fields(); | |
| 128 | + /* Product and Field */ | |
| 129 | + $products = Manage_Compare::instance()->get_compared_products_data(); | |
| 130 | + $fields = Manage_Compare::instance()->get_compare_fields(); | |
| 131 | 131 | |
| 132 | - $custom_heading = !empty( ever_compare_get_option( 'table_heading', 'ever_compare_table_settings_tabs' ) ) ? ever_compare_get_option( 'table_heading', 'ever_compare_table_settings_tabs' ) : array(); | |
| 132 | + $custom_heading = !empty( ever_compare_get_option( 'table_heading', 'ever_compare_table_settings_tabs' ) ) ? ever_compare_get_option( 'table_heading', 'ever_compare_table_settings_tabs' ) : array(); | |
| 133 | 133 | |
| 134 | - $default_atts = array( | |
| 135 | - 'evercompare' => Manage_Compare::instance(), | |
| 136 | - 'products' => $products, | |
| 137 | - 'fields' => $fields, | |
| 138 | - 'return_shop_button'=> $return_shop_button, | |
| 139 | - 'heading_txt' => $custom_heading, | |
| 140 | - 'empty_compare_text'=> $empty_compare_text, | |
| 141 | - ); | |
| 134 | + $default_atts = array( | |
| 135 | + 'evercompare' => Manage_Compare::instance(), | |
| 136 | + 'products' => $products, | |
| 137 | + 'fields' => $fields, | |
| 138 | + 'return_shop_button'=> $return_shop_button, | |
| 139 | + 'heading_txt' => $custom_heading, | |
| 140 | + 'empty_compare_text'=> $empty_compare_text, | |
| 141 | + ); | |
| 142 | 142 | |
| 143 | - $atts = shortcode_atts( $default_atts, $atts, $content ); | |
| 144 | - return Manage_Compare::instance()->table_html( $atts ); | |
| 143 | + $atts = shortcode_atts( $default_atts, $atts, $content ); | |
| 144 | + return Manage_Compare::instance()->table_html( $atts ); | |
| 145 | + } | |
| 145 | 146 | |
| 147 | + // Cookie-based: render placeholder that JS will populate via AJAX | |
| 148 | + return '<div class="htcompare-table" data-ajax-load="true"></div>'; | |
| 149 | + | |
| 146 | 150 | } |
| 147 | 151 | |
| 148 | 152 | /** |
| 149 | 153 | * Evercompare Counter Shortcode |
| @@ -157,9 +161,9 @@ | ||
| 157 | 161 | wp_enqueue_style( 'evercompare-frontend' ); |
| 158 | 162 | wp_enqueue_script( 'evercompare-frontend' ); |
| 159 | 163 | |
| 160 | 164 | $default_atts = array( |
| 161 | - 'count' => count(Manage_Compare::instance()->get_compared_products()), | |
| 165 | + 'count' => 0, | |
| 162 | 166 | 'page_url' => Manage_Compare::instance()->get_compare_page_url(), |
| 163 | 167 | ); |
| 164 | 168 | |
| 165 | 169 | $atts = shortcode_atts( $default_atts, $atts, $content ); |