public static function order_contains_sponsorship($order) { if (!is_object($order)) { $order = new WC_Order($order); } $contains_contribution = false; foreach ($order->get_items() as $order_item) { if (WC_Sponsorship_Product::is_sponsorship_contribution_level($order_item['product_id'])) { $contains_contribution = true; break; } } return $contains_contribution; }
function track_order($order) { if (!is_object($order)) { $order = new WC_Order($order); } $projects = array(); foreach ($order->get_items() as $order_item) { if (WC_Sponsorship_Product::is_sponsorship_contribution_level($order_item['product_id'])) { $cl = get_post($order_item['product_id']); if (!in_array($cl->post_parent, $projects)) { $projects[] = $cl->post_parent; } } } foreach ($projects as $project) { update_post_meta($order->id, '_sponsorship_project', $project); } }
public static function check_project_duedate($project_id) { $data = get_post_meta($project_id, '_sponsorship', true); $days_left = 0; if ($data['end']['date']) { $now = strtotime(date("Y-m-d")); // or your date as well $then = strtotime($data['end']['date']); $datediff = $then - $now; // add 1 additional day so if current day, it is not the last day $days_left = floor($datediff / (60 * 60 * 24)) + 1; if ($days_left < 0) { $days_left = 0; } } if (!$days_left) { $days_left = false; // cancel all orders WC_Sponsorship_Product::cancel_project_orders($project_id); } else { $days_left = true; } return $days_left; }
function get_wc_sponsorship_sidebar($name) { global $product; if (is_single() && WC_Sponsorship_Product::is_sponsorship($product) && 'Sponsorship Sidebar' != $name) { load_template($this->plugin_path() . '/classes/class-wc-sponsorship-sidebar.php', true); static $class = "wc-sponsorship-hidden"; $this->wc_sponsorship_sidebar_class_replace($class); } }