public function status_updated($request_id, $status) { $order_id = get_post_meta($request_id, '_order_id', true); $triggers = array('warranty_status'); FUE::create_order_from_triggers($order_id, $triggers); }
public static function suspended_subscription($user_id, $subs_key) { global $wpdb; $parts = explode('_', $subs_key); $order_id = $parts[0]; $item_id = $parts[1]; $order = new WC_Order($order_id); $items = $order->get_items(); $order_created = false; $triggers[] = 'subs_suspended'; FUE::create_order_from_triggers($order_id, $triggers); }
function new_order($order_id) { global $wpdb; $order = new WC_Order($order_id); $triggers = array(); FUE::record_order($order); if ($order->status == 'processing') { //$triggers[] = 'purchase'; $triggers[] = 'processing'; // add the date trigger $triggers[] = 'date'; // check for order_total $triggers[] = 'order_total_above'; $triggers[] = 'order_total_below'; $triggers[] = 'total_orders'; $triggers[] = 'total_purchases'; // check for first time purchase //$triggers[] = 'first_purchase'; // get the user's number of orders if ($order->user_id > 0) { $num_orders = $wpdb->get_var($wpdb->prepare("SELECT total_orders FROM {$wpdb->prefix}followup_customers WHERE user_id = %d", $order->user_id)); } else { $num_orders = $wpdb->get_var($wpdb->prepare("SELECT total_orders FROM {$wpdb->prefix}followup_customers WHERE email_address = %s", $order->billing_email)); } if ($num_orders == 1) { $triggers[] = 'first_purchase'; } if ($num_orders > 1) { $triggers[] = 'purchase_above_one'; } } elseif ($order->status == 'completed') { // if there are no order_items in the database, it's time to extract them from the order and insert into order_items if (0 == $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}followup_order_items WHERE order_id = {$order_id}")) { // extract items and categories $order_categories = array(); if (function_exists('get_product')) { $order_item_ids = $wpdb->get_results("SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = {$order_id}"); foreach ($order_item_ids as $order_item) { $product_id = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id = {$order_item->order_item_id} AND meta_key = '_product_id'"); if ($product_id) { $insert = array('order_id' => $order_id, 'product_id' => $product_id); $wpdb->insert($wpdb->prefix . 'followup_order_items', $insert); // get the categories $cat_ids = wp_get_post_terms($product_id, 'product_cat', array('fields' => 'ids')); if ($cat_ids) { foreach ($cat_ids as $cat_id) { $order_categories[] = $cat_id; } } } } } else { $order_items = get_post_meta($order_id, '_order_items', true); foreach ($order_items as $item) { $insert = array('order_id' => $order_id, 'product_id' => $item['id']); $wpdb->insert($wpdb->prefix . 'followup_order_items', $insert); // get the categories $cat_ids = wp_get_post_terms($item['id'], 'product_cat', array('fields' => 'ids')); if ($cat_ids) { foreach ($cat_ids as $cat_id) { $order_categories[] = $cat_id; } } } } $order_categories = array_unique($order_categories); foreach ($order_categories as $category_id) { $insert = array('order_id' => $order_id, 'category_id' => $category_id); $wpdb->insert($wpdb->prefix . 'followup_order_categories', $insert); } } // get the user's number of orders if ($order->user_id > 0) { $num_orders = $wpdb->get_var($wpdb->prepare("SELECT total_orders FROM {$wpdb->prefix}followup_customers WHERE user_id = %d", $order->user_id)); } else { $num_orders = $wpdb->get_var($wpdb->prepare("SELECT total_orders FROM {$wpdb->prefix}followup_customers WHERE email_address = %s", $order->billing_email)); } if ($num_orders == 1) { $triggers[] = 'first_purchase'; } if ($num_orders > 1) { $triggers[] = 'purchase_above_one'; } $triggers[] = $order->status; } else { $triggers[] = $order->status; } $triggers = apply_filters('fue_new_order_triggers', $triggers, $order_id); //echo '<pre>'. print_r($triggers, true) .'</pre>'; exit; FUE::create_order_from_triggers($order_id, $triggers); }
function new_order($order_id) { global $wpdb; $order = new WC_Order($order_id); $triggers = array(); if ($order->status == 'processing') { // see if this is a first purchase trigger $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `{$wpdb->prefix}postmeta` WHERE `meta_key` = '_billing_email' AND `meta_value` = %s", $order->billing_email)); if ($count == 1) { $triggers[] = 'first_purchase'; } $triggers[] = 'purchase'; $triggers[] = 'processing'; // add the date trigger $triggers[] = 'date'; } else { $triggers[] = $order->status; } $triggers = apply_filters('fue_new_order_triggers', $triggers, $order_id); FUE::create_order_from_triggers($order_id, $triggers); }