توضیحات تکمیلی
برند | OSS TEAM |
---|
/* Plugin Name: WooCommerce Price Sync to Crawler Description: Send product create/update/delete events to crawler server. Version: 1.1 Author: amirhossein azarniya */ // پوشه: wp-content/plugins/woo-price-sync/woo-price-sync.php // جلوگیری از اجرای در محیط غیر وردپرس if (!defined('ABSPATH')) exit; function send_to_crawler_api($data, $event) { $data['event'] = $event; $response = wp_remote_post('https://minoora.com/api/wordpress-sync?site_id=1', [ 'method' => 'POST', 'timeout' => 10, 'headers' => [ 'Content-Type' => 'application/json' ], 'body' => json_encode($data), ]); if (is_wp_error($response)) { error_log("[WooPriceSync] Error ($event): " . $response->get_error_message()); } else { error_log("[WooPriceSync] Sent $event for product ID {$data['id']}"); } } // 📤 بروزرسانی یا ایجاد محصول add_action('save_post_product', function ($post_id) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; if (get_post_status($post_id) !== 'publish') return; $product = wc_get_product($post_id); if (!$product) return; $data = [ 'id' => $post_id, 'price' => $product->get_regular_price(), 'sku' => $product->get_sku(), ]; send_to_crawler_api($data, 'updated'); }); // 🗑️ حذف محصول add_action('before_delete_post', function ($post_id) { if (get_post_type($post_id) !== 'product') return; $data = ['id' => $post_id]; send_to_crawler_api($data, 'deleted'); });