'Unauthorized']); // Temporarily override options for test if (!empty($_POST['api_url'])) update_option('alsaba_cz_api_url', sanitize_text_field($_POST['api_url'])); if (!empty($_POST['api_token'])) update_option('alsaba_cz_api_token', sanitize_text_field($_POST['api_token'])); $client = new AlSaba_CZ_API_Client(); $test = $client->test_connection(); if ($test['success']) { wp_send_json_success($test); } else { wp_send_json_error($test); } } public function ajax_run_sync() { check_ajax_referer('alsaba_cz_ajax_nonce'); if (!current_user_can('manage_woocommerce')) wp_send_json_error(['error' => 'Unauthorized']); $importer = new AlSaba_Product_Importer(); $result = $importer->execute_sync(); if ($result['success']) { wp_send_json_success($result); } else { wp_send_json_error($result); } } } new AlSaba_Admin_Settings(); ``` --- ## 8. WooCommerce Product Display Hooks (Custom Warranty Badges) Add this snippet to display the custom warranty duration and terms directly on the WooCommerce frontend product page and cart: ```php get_id(), '_alsaba_warranty_display', true); $warranty_type = get_post_meta($product->get_id(), '_alsaba_warranty_type', true); $warranty_terms = get_post_meta($product->get_id(), '_alsaba_warranty_terms', true); if (empty($warranty_display)) return; ?>
🛡️ Verified

✓ Cash on Delivery (COD) Doorstep Open-Box Inspection Allowed
__('Warranty Guarantee', 'alsaba-cz-sync'), 'value' => esc_html($cart_item['alsaba_warranty']) ]; } return $item_data; } ``` --- ## 9. How to Install & Use on Your WordPress / WooCommerce Site 1. **Create the Folder:** In your WordPress site, go to `wp-content/plugins/` and create a directory named `alsaba-cz-sync/`. 2. **Save Files:** Place the PHP code files in the structure outlined in Section 1. 3. **Activate:** Go to **WP-Admin > Plugins > Installed Plugins** and click **Activate** on **Al Saba Computer — Vendor API Sync & Custom Warranty Engine**. 4. **Configure:** - Navigate to **WooCommerce > Vendor API Sync**. - Paste your secret bearer token (`your_secret_token_here`). - Set your markup percentage (e.g. `12%`). - Click **"Test Connection"** to verify against `api.computerzone.pk`. - Click **"Run Sync Now (cURL)"** to import products immediately or let the hourly cron run automatically. 5. **Custom Warranty Integration:** Every imported product automatically gets mapped to its custom warranty duration (14-day checking, 3-year brand, 5-year SSD), displays on single product pages, and attaches to the order receipt at checkout. })();
TEST • All screens