Changeset 3331483
- Timestamp:
- 07/21/2025 12:30:05 PM (9 months ago)
- Location:
- pasazh/trunk
- Files:
-
- 2 edited
-
pasazh.php (modified) (9 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pasazh/trunk/pasazh.php
r3330622 r3331483 6 6 Plugin URI: https://epasazh.com 7 7 Description: Using this plugin, you can connect your store to Pasazh. Just activate it, then go to your admin panel on the Pasazh website and complete the remaining steps to establish the connection. 8 Version: 1. 198 Version: 1.20 9 9 Author: aliparsa 10 10 Author URI: https://profiles.wordpress.org/aliparsa/ … … 12 12 License URI: https://www.gnu.org/licenses/gpl-2.0.html 13 13 Domain Path: /languages 14 Text Domain: my-toolset14 Text Domain: Pasazh 15 15 */ 16 16 17 const PASAZHAPI_papi_version = "1. 19";17 const PASAZHAPI_papi_version = "1.20"; 18 18 add_action('rest_api_init', function () { 19 19 register_rest_route('papi', '/products', array( … … 39 39 add_action('deleted_post', 'PASAZHAPI_delete_product'); 40 40 add_action('save_post', 'PASAZHAPI_sync_product'); 41 add_action('woocommerce_payment_complete', 'handle_payment_complete'); 42 add_action('woocommerce_order_status_changed', 'handle_order_status_changed', 10, 4); 43 const BASE_WEBHOOK_URL = "https://epasazh.com/api/webhooks/woocommerce"; 41 44 42 45 //region api functions 46 47 function handle_order_status_changed($order_id, $old_status, $new_status, $order) { 48 if ($new_status === 'cancelled') { 49 foreach ($order->get_items() as $item) { 50 $product_id = $item->get_product_id(); 51 if (!$product_id) continue; 52 PASAZHAPI_sync_product($product_id); 53 } 54 } 55 } 56 57 function handle_payment_complete($order_id) { 58 $order = wc_get_order($order_id); 59 if (!$order) return; 60 61 $order_status = $order->get_status(); 62 63 if($order_status !== "processing") 64 return; 65 66 foreach ($order->get_items() as $item) { 67 $product_id = $item->get_product_id(); 68 if (!$product_id) continue; 69 PASAZHAPI_sync_product($product_id); 70 } 71 72 } 43 73 44 74 function PASAZHAPI_info($product_id) … … 71 101 } 72 102 103 if(isset($query['field'])){ 104 $query['return'] = $query['field']; 105 unset($query['field']); 106 } 107 73 108 $pasazh_products = []; 74 109 $items = wc_get_products($query); 75 76 if(is_int($items[0])){ 77 foreach ($items as $productId) { 78 $pasazh_products[] = $productId; 79 } 80 }else{ 81 foreach ($items as $product) { 82 $product->description = apply_filters( 'the_content', $product->description ); 83 $pasazh_product = PASAZHAPI_get_pasazh_product_from_wc_product($product); 84 $pasazh_products[] = $pasazh_product; 85 } 86 } 87 110 if(count($items) > 0){ 111 if(is_int($items[0])){ 112 foreach ($items as $productId) { 113 $pasazh_products[] = $productId; 114 } 115 }else{ 116 foreach ($items as $product) { 117 $pasazh_product = PASAZHAPI_get_pasazh_product_from_wc_product($product); 118 $pasazh_products[] = $pasazh_product; 119 } 120 } 121 } 88 122 $response = []; 89 123 $response["meta"] = [ … … 91 125 ]; 92 126 $response["products"] = $pasazh_products; 93 94 127 return new WP_REST_Response($response, 200); 95 128 } … … 107 140 if ($post_type != "product") return; 108 141 109 wp_remote_get( "https://epasazh.com/api/webhooks/woocommerce/addon-product-deleted/$product_id", [142 wp_remote_get(BASE_WEBHOOK_URL . "/addon-product-deleted/$product_id", [ 110 143 "headers" => [ 111 144 "papi-source-url" => get_site_url() … … 120 153 if (get_transient("papi_product_id") == $product_id) return; 121 154 set_transient('papi_product_id', $product_id, 1); 122 123 155 $post = get_post($product_id); 124 156 if (!$post) return; … … 134 166 } 135 167 136 wp_remote_get("https://epasazh.com/api/webhooks/woocommerce/addon-product-updated/$product_id", [168 $res = wp_remote_get(BASE_WEBHOOK_URL . "/addon-product-updated/$product_id", [ 137 169 "headers" => [ 138 170 "papi-source-url" => get_site_url() 139 171 ] 140 172 ]); 141 } catch (Exception $e) {} 173 } catch (Exception $e) { 174 error_log($e->getMessage()); 175 } 142 176 } 143 177 … … 202 236 $pasazh_product->attributes = $attributes; 203 237 204 $description = $product->get_description();238 $description = apply_filters( 'the_content', $product->get_description() ); 205 239 206 240 if (strlen($description) == 0) { -
pasazh/trunk/readme.txt
r3330622 r3331483 5 5 Requires at least: 5.0.3 6 6 Tested up to: 5.9.3 7 Stable tag: 1. 197 Stable tag: 1.20 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 23 23 == Screenshots == 24 24 == Changelog == 25 = 1. 19=25 = 1.20 = 26 26 * First release 27 27 == Upgrade Notice ==
Note: See TracChangeset
for help on using the changeset viewer.