コード例 #1
0
 function add_product_validation($valid, $product_id, $quantity)
 {
     global $woocommerce;
     if (WC_Sponsorship_Product::is_sponsorship_contribution_level($product_id)) {
         $woocommerce->cart->empty_cart();
     } elseif (WC_Sponsorship::cart_contains_sponsorship_contribution()) {
         WC_Sponsorship::remove_sponsorship_from_cart();
         $woocommerce->add_error('A sponsorship contribution has been removed from your cart. Due to payment gateway restrictions, products can not be purchased at the same time.');
         $woocommerce->set_messages();
         // Redirect to cart page to remove subscription & notify shopper
         add_filter('add_to_cart_fragments', array(&$this, 'redirect_ajax_add_to_cart'));
     }
     return true;
 }
コード例 #2
0
 public static function is_sponsorship_contribution_level($product)
 {
     return WC_Sponsorship::is_sponsorship_contribution_level($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);