css
2 years ago
img
2 years ago
js
2 years ago
partials
2 years ago
class-email.php
2 years ago
class-eqw-advance.php
2 years ago
class-eqw-enquiry-cart.php
2 years ago
class-eqw-enquiry-shortcode.php
2 years ago
class-eqw-product.php
2 years ago
class-eqw-save-enquiry.php
2 years ago
class-pisol-enquiry-quotation-woocommerce-public.php
2 years ago
class-pisol-form.php
2 years ago
class-webhook.php
2 years ago
index.php
2 years ago
class-webhook.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | class pisol_eqw_webhook{ |
| 4 | |
| 5 | static $instance = null; |
| 6 | |
| 7 | static function instance(){ |
| 8 | if(self::$instance == null){ |
| 9 | self::$instance = new self(); |
| 10 | } |
| 11 | return self::$instance; |
| 12 | } |
| 13 | |
| 14 | function __construct(){ |
| 15 | add_action('pisol_eqw_enquiry_saved', [$this, 'sendWebhook']); |
| 16 | } |
| 17 | |
| 18 | function sendWebhook($enq_id){ |
| 19 | $webhook_url = get_option('pi_eqw_webhook_url', ''); |
| 20 | |
| 21 | if(empty($webhook_url)){ |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | $meta_data = get_post_meta($enq_id); |
| 26 | |
| 27 | if(empty($meta_data) || !is_array($meta_data)){ |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | foreach ($meta_data as $key => $values) { |
| 32 | // Check if the value is an array and has at least one element |
| 33 | if (is_array($values) && count($values) > 0) { |
| 34 | // Assign the first value directly to a variable with the meta key as the variable name |
| 35 | $meta_data[$key] = $values[0]; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | $meta_data['pi_products_info'] = unserialize(get_post_meta($enq_id, 'pi_products_info', true)); |
| 40 | |
| 41 | if(!empty($meta_data)){ |
| 42 | try{ |
| 43 | $response = wp_remote_post($webhook_url, array( |
| 44 | 'body' => json_encode($meta_data), |
| 45 | 'headers' => array('Content-Type' => 'application/json'), |
| 46 | )); |
| 47 | }catch(Exception $e){ |
| 48 | error_log($e->getMessage()); |
| 49 | return; |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | pisol_eqw_webhook::instance(); |