示例#1
0
 /**
  * Preparing the valid offer to show
  */
 function prepare_offer($display_as, $offers_data)
 {
     global $sa_smart_offers;
     extract($offers_data);
     // Show offer
     if (!empty($offer_data)) {
         $show_offer_as_popup = !empty($display_as) ? $display_as : '';
         $js = $this->get_offer_js();
         if (!wp_script_is('jquery')) {
             wp_enqueue_script('jquery');
         }
         $sa_smart_offers->enqueue_js($js);
         if (count($offer_data) > 1) {
             $show_offer_as_popup = "inline";
         }
         foreach ($offer_data as $data) {
             $this->show_offer($data, $page, $where_url, $show_offer_as_popup);
         }
     } else {
         if ($skipped_offer_id_variable && !empty($where_url)) {
             ob_clean();
             if (SO_Session_Handler::check_session_set_or_not($skip_offer_id_variable)) {
                 SO_Session_Handler::so_delete_session($skip_offer_id_variable);
             }
             wp_safe_redirect($where_url);
             exit;
         }
     }
 }
示例#2
0
 /**
  * Empty SO related session data on logout
  */
 function so_clear_session()
 {
     global $sa_smart_offers;
     SO_Session_Handler::so_delete_session('sa_smart_offers_skipped_offer_ids');
     SO_Session_Handler::so_delete_session('sa_smart_offers_accepted_offer_ids');
     $pages = array('cart', 'checkout', 'thankyou', 'myaccount', 'home', 'any');
     foreach ($pages as $page) {
         SO_Session_Handler::so_delete_session($page . '_skip_offer_id');
         SO_Session_Handler::so_delete_session($page . '_parent_offer_id');
     }
     if ($sa_smart_offers->is_wc_gte_21()) {
         $data = !empty($sa_smart_offers->global_wc()->session) ? get_option('_wc_session_' . $sa_smart_offers->global_wc()->session->get_customer_id(), array()) : null;
     } else {
         $data = $_SESSION;
     }
     if (!empty($data)) {
         foreach ($data as $key_name => $value) {
             if (strpos($key_name, '_skip_offer_id') !== false || strpos($key_name, '_parent_offer_id') !== false) {
                 SO_Session_Handler::so_delete_session($key_name);
             }
         }
     }
 }
示例#3
0
 /**
  * Return valid offers in a page
  */
 function get_valid_offer_ids($data)
 {
     if (empty($data)) {
         return;
     }
     extract($data);
     $valid_offer_ids = array();
     if (!empty($offer_id_on_skipping)) {
         $unset_id = false;
         $offer_id = $offer_id_on_skipping;
         if (!is_array($skipped_ids_in_session)) {
             $skipped_ids_in_session = explode(',', $skipped_ids_in_session);
         }
         if (!empty($skipped_ids_in_session) || !empty($accepted_ids_in_session)) {
             if (in_array($offer_id_on_skipping, $skipped_ids_in_session) || in_array($offer_id_on_skipping, $accepted_ids_in_session)) {
                 $unset_id = true;
             }
         }
         if ($unset_id == true) {
             SO_Session_Handler::so_delete_session($skip_offer_id_variable);
         } else {
             $so_offer = new SO_Offer();
             //$offer_price = get_post_meta( $offer_id, 'offer_price', true ); // Need to fetch price based on variation id, variation data, prod_id
             $offer_price = $so_offer->get_offer_price(array('offer_id' => $offer_id));
             $valid_offer_ids[$offer_id] = $offer_price;
         }
     } else {
         $parent_offer_id_variable = $where == "any" ? str_replace(array('/', '-', '&', '=', ':'), '', $where_url) . '_parent_offer_id' : $where . '_parent_offer_id';
         $check_parent_offer_id = SO_Session_Handler::check_session_set_or_not($parent_offer_id_variable);
         if ($check_parent_offer_id) {
             SO_Session_Handler::so_delete_session($parent_offer_id_variable);
         }
         if (!empty($offer_ids)) {
             // get offers based on ids for future
             $offer_ids = explode(',', $offer_ids);
             $offer_ids = $this->get_page_offers($page, $offer_ids);
         } else {
             $offer_ids = $this->get_page_offers($page);
         }
         if (!empty($offer_ids)) {
             //Get user's details
             $user_details = $where == "thankyou" ? $this->get_user_details($page, $order) : $this->get_user_details($page, '');
             // Get Cart/Order details
             $cart_order_details = $where == "thankyou" ? $current_order_details : $this->get_cart_contents();
             $details = array_merge($user_details, $cart_order_details);
             $valid_offer_ids = $this->validate_offers($page, $offer_ids, $details);
         } else {
             return;
         }
     }
     if (empty($valid_offer_ids)) {
         return;
     }
     return $valid_offer_ids;
 }