'POST', 'callback' => [$this, 'handle_chat'], 'permission_callback' => [$this, 'verify_rest_nonce'] ]); } public function verify_rest_nonce(\WP_REST_Request $request) { $nonce = $request->get_header('X-WP-Nonce'); if ($nonce && wp_verify_nonce($nonce, 'wp_rest')) { return true; } return new \WP_Error('rest_forbidden', __('Access Denied: Invalid security token.', 'ai-conversational-commerce-assistant-for-woocommerce'), ['status' => 403]); } public function get_product_card() { check_ajax_referer('shoponix_chat_nonce', 'nonce'); $product_id = isset($_POST['product_id']) ? intval(wp_unslash($_POST['product_id'])) : 0; if (!$product_id) wp_send_json_error(); $product = wc_get_product($product_id); if (!$product) wp_send_json_error(); $type = $product->get_type(); $name = $product->get_name(); ob_start(); ?>
| Price | |
| Stock | |
| Sizes Available | |
| Colors Available | |
| Feature | get_image([40, 40], ['style' => 'border-radius: 6px; object-fit: cover; width: 40px; height: 40px; display: block; margin: 0 auto 6px;'])); ?> |
|---|---|
| Price | get_price_html()); ?> |
| Rating | get_average_rating(); echo esc_html($rating > 0 ? str_repeat('⭐', round($rating)) . ' (' . $p->get_review_count() . ')' : 'No reviews'); ?> |
| Stock | is_in_stock() ? 'In Stock' : 'Out of Stock'; ?> |
| Short Info | get_short_description()), 8, '...')); ?> |
| get_type() === 'variable'): ?> |