| @@ -59,13 +59,28 @@ | ||
| 59 | 59 | if (!Wishlist_Settings::is_enabled()) { |
| 60 | 60 | return; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | + $style_path = KING_ADDONS_PATH . 'includes/wishlist/assets/style.css'; | |
| 64 | + $script_path = KING_ADDONS_PATH . 'includes/wishlist/assets/script.js'; | |
| 65 | + $style_ver = file_exists($style_path) ? (string) filemtime($style_path) : KING_ADDONS_VERSION; | |
| 66 | + $script_ver = file_exists($script_path) ? (string) filemtime($script_path) : KING_ADDONS_VERSION; | |
| 67 | + | |
| 68 | + $style_deps = []; | |
| 69 | + if (wp_style_is('font-awesome-5-all', 'registered')) { | |
| 70 | + wp_enqueue_style('font-awesome-5-all'); | |
| 71 | + $style_deps[] = 'font-awesome-5-all'; | |
| 72 | + } | |
| 73 | + if (wp_style_is('elementor-icons', 'registered')) { | |
| 74 | + wp_enqueue_style('elementor-icons'); | |
| 75 | + $style_deps[] = 'elementor-icons'; | |
| 76 | + } | |
| 77 | + | |
| 63 | 78 | wp_enqueue_style( |
| 64 | 79 | 'king-addons-wishlist', |
| 65 | 80 | KING_ADDONS_URL . 'includes/wishlist/assets/style.css', |
| 66 | - [], | |
| 67 | - KING_ADDONS_VERSION | |
| 81 | + $style_deps, | |
| 82 | + $style_ver | |
| 68 | 83 | ); |
| 69 | 84 | |
| 70 | 85 | wp_enqueue_script( |
| 71 | 86 | 'king-addons-wishlist', |
| @@ -70,9 +85,9 @@ | ||
| 70 | 85 | wp_enqueue_script( |
| 71 | 86 | 'king-addons-wishlist', |
| 72 | 87 | KING_ADDONS_URL . 'includes/wishlist/assets/script.js', |
| 73 | 88 | ['jquery'], |
| 74 | - KING_ADDONS_VERSION, | |
| 89 | + $script_ver, | |
| 75 | 90 | true |
| 76 | 91 | ); |
| 77 | 92 | |
| 78 | 93 | wp_localize_script( |
| @@ -84,8 +99,9 @@ | ||
| 84 | 99 | 'labels' => [ |
| 85 | 100 | 'added' => Wishlist_Settings::get('button_added_text'), |
| 86 | 101 | 'add' => Wishlist_Settings::get('button_add_text'), |
| 87 | 102 | 'error' => esc_html__('Unable to update wishlist. Please try again.', 'king-addons'), |
| 103 | + 'empty' => esc_html__('No products in wishlist yet.', 'king-addons'), | |
| 88 | 104 | ], |
| 89 | 105 | ] |
| 90 | 106 | ); |
| 91 | 107 | } |
| @@ -109,8 +125,12 @@ | ||
| 109 | 125 | if (!$product_id) { |
| 110 | 126 | wp_send_json_error(['message' => esc_html__('Product id is required.', 'king-addons')], 400); |
| 111 | 127 | } |
| 112 | 128 | |
| 129 | + if (!function_exists('wc_get_product') || !wc_get_product($product_id)) { | |
| 130 | + wp_send_json_error(['message' => esc_html__('Product id is required.', 'king-addons')], 400); | |
| 131 | + } | |
| 132 | + | |
| 113 | 133 | if (!Wishlist_Settings::guests_allowed() && !is_user_logged_in()) { |
| 114 | 134 | wp_send_json_error(['message' => esc_html__('Please sign in to use wishlist.', 'king-addons')], 403); |
| 115 | 135 | } |
| 116 | 136 | |
| @@ -122,8 +142,11 @@ | ||
| 122 | 142 | wp_send_json_success([ |
| 123 | 143 | 'wishlist_id' => $result['wishlist_id'], |
| 124 | 144 | 'count' => $result['count'], |
| 125 | 145 | 'state' => !empty($result['success']) ? ($this->service->has_item($product_id, $variation_id, $wishlist_id) ? 'added' : 'default') : 'default', |
| 146 | + 'page_html' => $this->shortcode_page([ | |
| 147 | + 'wishlist_id' => $result['wishlist_id'] ?? '', | |
| 148 | + ]), | |
| 126 | 149 | ]); |
| 127 | 150 | } |
| 128 | 151 | |
| 129 | 152 | /** |
| @@ -373,9 +396,10 @@ | ||
| 373 | 396 | return $this->render_notes_cell($item); |
| 374 | 397 | case 'add_to_cart': |
| 375 | 398 | return $this->render_add_to_cart_button($product); |
| 376 | 399 | case 'remove': |
| 377 | - return '<button type="button" class="king-addons-wishlist-button king-addons-wishlist-button--table-remove" data-product-id="' . esc_attr($item->product_id) . '" data-variation-id="' . esc_attr($item->variation_id) . '" data-wishlist-id="' . esc_attr($item->wishlist_id) . '"><span class="king-addons-wishlist-button__label">' . esc_html__('Remove', 'king-addons') . '</span></button>'; | |
| 400 | + $remove_label = esc_html__('Remove', 'king-addons'); | |
| 401 | + return '<button type="button" class="king-addons-wishlist-button king-addons-wishlist-button--table-remove" data-product-id="' . esc_attr($item->product_id) . '" data-variation-id="' . esc_attr($item->variation_id) . '" data-wishlist-id="' . esc_attr($item->wishlist_id) . '" data-label-default="' . esc_attr($remove_label) . '" data-label-added="' . esc_attr($remove_label) . '"><span class="king-addons-wishlist-button__label">' . $remove_label . '</span></button>'; | |
| 378 | 402 | default: |
| 379 | 403 | return ''; |
| 380 | 404 | } |
| 381 | 405 | } |