function is_sponsorship_contribution_level($product) { if (!is_object($product)) { $product = new WC_Product_Variable($product); } $prod_post = $product->post; if (!$prod_post) { $prod_post = get_post($product->id); } if ($prod_post->post_parent) { return WC_Sponsorship::is_sponsorship($prod_post->post_parent); } return false; }
public static function is_sponsorship($product) { return WC_Sponsorship::is_sponsorship($product); }
<?php global $post, $product, $wpdb; if (!is_object($product)) { $product = new WC_Product_Variable($product); } if (!WC_Sponsorship::is_sponsorship($product)) { return; } $data = get_post_meta($post->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']); $end_date = date("l M j", $then); $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; } } $goal = $progress = $percent = 0; if (array_key_exists('goal', $data)) { $goal = $data['goal']; } if (array_key_exists('progress', $data)) { $progress = $data['progress']; if ($goal) { $percent = round($data['progress'] / $data['goal'] * 100);