public function add_subscription_args($args, $offer_id, $action) { if (empty($args) || $action == 'skip') { return $args; } $so_offers = new SO_Offers(); $user_details = $so_offers->get_user_details(); $user_has_bought = !empty($user_details['offer_rule_has_bought']) ? explode(',', $user_details['offer_rule_has_bought']) : array(); $subscriptions = WC_Subscriptions_Manager::get_users_subscriptions(); $preserve_keys = true; $subscriptions = array_reverse($subscriptions, $preserve_keys); foreach ($subscriptions as $subscription_key => $subscription) { if (in_array($subscription['product_id'], $user_has_bought) && 'active' == $subscription['status']) { $args['switch-subscription'] = $subscription_key; $args['auto-switch'] = 'true'; break; } } return $args; }
function is_offer_valid($page, $offer_ids) { global $sa_smart_offers; $so_offers = new SO_Offers(); //Get user's details $user_details = $so_offers->get_user_details($page, ''); $dp = (int) get_option('woocommerce_price_num_decimals'); $sa_smart_offers->global_wc()->cart->calculate_shipping(); if ($sa_smart_offers->is_wc_gte_20()) { if ($sa_smart_offers->is_wc_gte_23()) { $cart_total = apply_filters('woocommerce_calculated_total', round($sa_smart_offers->global_wc()->cart->cart_contents_total + $sa_smart_offers->global_wc()->cart->tax_total + $sa_smart_offers->global_wc()->cart->shipping_tax_total + $sa_smart_offers->global_wc()->cart->shipping_total + $sa_smart_offers->global_wc()->cart->fee_total, $sa_smart_offers->global_wc()->cart->dp), $sa_smart_offers->global_wc()->cart); } else { $cart_total = apply_filters('woocommerce_calculated_total', number_format($sa_smart_offers->global_wc()->cart->cart_contents_total + $sa_smart_offers->global_wc()->cart->tax_total + $sa_smart_offers->global_wc()->cart->shipping_tax_total + $sa_smart_offers->global_wc()->cart->shipping_total - $sa_smart_offers->global_wc()->cart->discount_total + $sa_smart_offers->global_wc()->cart->fee_total, $dp, '.', ''), $sa_smart_offers->global_wc()->cart); } } else { $cart_total = apply_filters('woocommerce_calculated_total', number_format($sa_smart_offers->global_wc()->cart->cart_contents_total + $sa_smart_offers->global_wc()->cart->tax_total + $sa_smart_offers->global_wc()->cart->shipping_tax_total + $sa_smart_offers->global_wc()->cart->shipping_total - $sa_smart_offers->global_wc()->cart->discount_total, $dp, '.', ''), $sa_smart_offers->global_wc()->cart); } // Get Cart/Order details $cart_order_details = $so_offers->get_cart_contents(); $cart_order_details['offer_rule_grand_total'] = $cart_total; $details = array_merge($user_details, $cart_order_details); $offer_to_validate = $so_offers->get_all_offer_rules_meta($offer_ids); $valid_offer_ids = $so_offers->validate_offers($page, $offer_to_validate, $details); $key = !empty($offer_ids[0]) ? $offer_ids[0] : 0; if (!empty($valid_offer_ids) && array_key_exists($key, $valid_offer_ids)) { return $valid_offer_ids; } else { return false; } }