コード例 #1
2
/**
 * Track product views.
 */
function wc_track_product_view()
{
    if (!is_singular('product') || !is_active_widget(false, false, 'woocommerce_recently_viewed_products', true)) {
        return;
    }
    global $post;
    if (empty($_COOKIE['woocommerce_recently_viewed'])) {
        $viewed_products = array();
    } else {
        $viewed_products = (array) explode('|', $_COOKIE['woocommerce_recently_viewed']);
    }
    if (!in_array($post->ID, $viewed_products)) {
        $viewed_products[] = $post->ID;
    }
    if (sizeof($viewed_products) > 15) {
        array_shift($viewed_products);
    }
    // Store for session only
    wc_setcookie('woocommerce_recently_viewed', implode('|', $viewed_products));
}
コード例 #2
0
function as_add_cookie($name, $value, $expire = 0)
{
    if ($expire == 0) {
        $expire = time() + 60 * 60 * 24 * 30;
    }
    $value = json_encode(stripslashes_deep($value));
    $_COOKIE[WISHLIST_COOKIE_NAME] = $value;
    wc_setcookie($name, $value, $expire, false);
}
コード例 #3
0
 /**
  * Sets the session cookie on-demand (usually after adding an item to the cart).
  *
  * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set.
  *
  * Warning: Cookies will only be set if this is called before the headers are sent.
  */
 public function set_customer_session_cookie($set)
 {
     if ($set) {
         // Set/renew our cookie
         $to_hash = $this->_customer_id . $this->_session_expiration;
         $cookie_hash = hash_hmac('md5', $to_hash, wp_hash($to_hash));
         $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash;
         // Set the cookie
         wc_setcookie($this->_cookie, $cookie_value, $this->_session_expiration);
     }
 }
コード例 #4
0
 /**
  * Sets the session cookie on-demand (usually after adding an item to the cart).
  *
  * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set.
  *
  * Warning: Cookies will only be set if this is called before the headers are sent.
  */
 public function set_customer_session_cookie($set)
 {
     if ($set) {
         // Set/renew our cookie
         $to_hash = $this->_customer_id . $this->_session_expiration;
         $cookie_hash = hash_hmac('md5', $to_hash, wp_hash($to_hash));
         $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash;
         $this->_has_cookie = true;
         // Set the cookie
         wc_setcookie($this->_cookie, $cookie_value, $this->_session_expiration, apply_filters('wc_session_use_secure_cookie', false));
     }
 }
コード例 #5
0
 /**
  * Destroy all session data.
  */
 public function destroy_session()
 {
     // Clear cookie
     wc_setcookie($this->_cookie, '', time() - YEAR_IN_SECONDS, apply_filters('wc_session_use_secure_cookie', false));
     $this->delete_session($this->_customer_id);
     // Clear cart
     wc_empty_cart();
     // Clear data
     $this->_data = array();
     $this->_dirty = false;
     $this->_customer_id = $this->generate_customer_id();
 }
コード例 #6
0
 /**
  * Set cart hash cookie and items in cart.
  *
  * @access private
  * @param bool $set (default: true)
  */
 private function set_cart_cookies($set = true)
 {
     if ($set) {
         wc_setcookie('woocommerce_items_in_cart', 1);
         wc_setcookie('woocommerce_cart_hash', md5(json_encode($this->get_cart_for_session())));
     } elseif (isset($_COOKIE['woocommerce_items_in_cart'])) {
         wc_setcookie('woocommerce_items_in_cart', 0, time() - HOUR_IN_SECONDS);
         wc_setcookie('woocommerce_cart_hash', '', time() - HOUR_IN_SECONDS);
     }
     do_action('woocommerce_set_cart_cookies', $set);
 }
コード例 #7
0
 /**
  * Create a cookie.
  * 
  * @param string $name
  * @param mixed $value
  * @return bool
  * @since 1.0.0
  */
 function yith_setcookie($name, $value = array(), $time = null)
 {
     $time = $time != null ? $time : time() + apply_filters('yith_wcwl_cookie_expiration', 60 * 60 * 24 * 30);
     //$value = maybe_serialize( stripslashes_deep( $value ) );
     $value = json_encode(stripslashes_deep($value));
     $expiration = apply_filters('yith_wcwl_cookie_expiration_time', $time);
     // Default 30 days
     $_COOKIE[$name] = $value;
     wc_setcookie($name, $value, $expiration, false);
 }
コード例 #8
0
 /**
  * function to get unique id for user, create new if not already set
  */
 static function so_get_customer_id()
 {
     global $sa_smart_offers;
     $so_guest_id = !empty($_COOKIE['so_guest_id']) ? $_COOKIE['so_guest_id'] : null;
     if (empty($so_guest_id)) {
         $so_guest_id = $sa_smart_offers->global_wc()->session->get_customer_id();
         wc_setcookie('so_guest_id', $so_guest_id, time() + 60 * 60 * 48, apply_filters('wc_session_use_secure_cookie', false));
     }
     return $so_guest_id;
 }
コード例 #9
0
 /**
  * Set hash cookie and items in raq.
  *
  * @since  1.0.0
  * @access private
  * @return void
  * @author Emanuela Castorina
  */
 private function set_rqa_cookies($set = true)
 {
     if ($set) {
         wc_setcookie('yith_ywraq_items_in_raq', 1);
         wc_setcookie('yith_ywraq_hash', md5(json_encode($this->raq_content)));
     } elseif (isset($_COOKIE['yith_ywraq_items_in_raq'])) {
         wc_setcookie('yith_ywraq_items_in_raq', 0, time() - HOUR_IN_SECONDS);
         wc_setcookie('yith_ywraq_hash', '', time() - HOUR_IN_SECONDS);
     }
     do_action('yith_ywraq_set_rqa_cookies', $set);
 }
 /**
  * Create a cookie on page with temp user id
  * @return  void
  */
 public function create_temp_user_cookie()
 {
     if (!isset($_COOKIE['graphflow'])) {
         if (!is_user_logged_in()) {
             $user_id = wp_generate_password(32, false);
             wc_setcookie('graphflow', $user_id, time() + 60 * 60 * 24 * 365);
             $_REQUEST['graphflow_req_id'] = $user_id;
         }
     }
 }
 function fz_visacheckout_load_from_callid($fields)
 {
     $payment_gateways = WC()->payment_gateways->get_available_payment_gateways();
     if (!isset($payment_gateways['fatzebra_visacheckout'])) {
         return $fields;
     }
     $gw = $payment_gateways['fatzebra_visacheckout'];
     $callid = isset($_COOKIE['fatzebra_visacheckout_callid']) ? $_COOKIE['fatzebra_visacheckout_callid'] : null;
     if (empty($callid)) {
         return $fields;
     }
     $token_result = $gw->tokenize_card(array("callid" => $callid));
     if (is_wp_error($token_result)) {
         // Tokenization error - for now lets return the fields with no manipulation..
         // error_log
         return $fields;
     }
     // Arghhh!
     $wallet = $token_result['wallet'];
     // Store the wallet data in a session. It is important to remove this upon successful checkout....
     WC()->session->set('visa_wallet_first_name', $wallet->name->first);
     WC()->session->set('visa_wallet_last_name', $wallet->name->last);
     WC()->session->set('visa_wallet_address_1', $wallet->address->line_1);
     WC()->session->set('visa_wallet_address_2', $wallet->address->line_2);
     WC()->session->set('visa_wallet_city', $wallet->address->city);
     WC()->session->set('visa_wallet_state', $wallet->address->state);
     WC()->session->set('visa_wallet_postcode', $wallet->address->postcode);
     WC()->session->set('visa_wallet_phone', $wallet->address->phone);
     WC()->session->set('visa_wallet_email', $wallet->email);
     WC()->session->set('visa_wallet_callid', $callid);
     WC()->session->set('visa_wallet_token', $token_result['card_token']);
     WC()->session->set('visa_wallet_masked_number', $token_result['card_number']);
     wc_setcookie('fatzebra_visacheckout_callid', null, time() - 3600);
     return $fields;
 }
コード例 #12
0
 public function checkfermopoint_book_fieldupdate($order_id, $posted)
 {
     if (isset($_COOKIE['fermopoint_session'])) {
         $fermopoint_session = stripslashes($_COOKIE['fermopoint_session']);
         $fermopoint_session = json_decode($fermopoint_session);
         $url = $fermopoint_session->Links->GetBookingUrl;
         $url_approval = $fermopoint_session->Links->ApprovalUrl;
         $url_reject = $fermopoint_session->Links->RejectionUrl;
         $ch = curl_init();
         $connect_timeout = 5;
         //sec
         //$request = $_POST["request"];
         // $url = $_POST["urlfermo"];
         $base_time_limit = (int) ini_get('max_execution_time');
         if ($base_time_limit < 0) {
             $base_time_limit = 0;
         }
         $time_limit = $base_time_limit - $connect_timeout - 2;
         if ($time_limit <= 0) {
             $time_limit = 20;
             //default
         }
         $httpHeader = array("Content-Type: application/json; charset=\"utf-8\"");
         curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
         //curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connect_timeout);
         curl_setopt($ch, CURLOPT_TIMEOUT, $time_limit);
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $result = curl_exec($ch);
         if (!curl_errno($ch)) {
             $ret = json_decode($result);
             update_post_meta($order_id, '_shipping_first_name', $ret->Nickname);
             update_post_meta($order_id, '_shipping_last_name', " - " . $ret->PointName . " - Fermo!Point");
             update_post_meta($order_id, '_shipping_company', "");
             update_post_meta($order_id, '_shipping_address_1', $ret->Address->Street);
             update_post_meta($order_id, '_shipping_address_2', $ret->Address->Extended);
             update_post_meta($order_id, '_shipping_postcode', $ret->Address->PostalCode);
             update_post_meta($order_id, '_shipping_city', $ret->Address->Locality . " " . $ret->Address->City);
             update_post_meta($order_id, '_shipping_state', $ret->Address->District);
             update_post_meta($order_id, '_shipping_postcode', $ret->Address->PostalCode);
             update_post_meta($order_id, '_shipping_country', "IT");
             //var_dump($ret);
             update_post_meta($order_id, '_shipping_ticketId-fermopoint', $ret->TicketId);
             update_post_meta($order_id, '_shipping_urlticket-fermopoint', $ret->BookingUrl);
             update_post_meta($order_id, '_shipping_statebook-fermopoint', $ret->State);
             update_post_meta($order_id, '_shipping_statenote-fermopoint', $ret->Notes);
             update_post_meta($order_id, '_shipping_approvalUrl-fermopoint', $url_approval);
             update_post_meta($order_id, '_shipping_rejectUrl-fermopoint', $url_reject);
         }
         curl_close($ch);
         wc_setcookie('fermopoint_session', "", strtotime('-1 day'));
         wc_setcookie('fermopoint_invio', "", strtotime('-1 day'));
     }
 }
コード例 #13
0
 /**
  * Purchase a job package
  * @param  int|string $package_id
  * @param  int $job_id
  * @return bool Did it work or not?
  */
 private static function process_package($package_id, $is_user_package, $job_id)
 {
     if ($is_user_package) {
         $user_package = wc_paid_listings_get_user_package($package_id);
         $package = wc_get_product($user_package->get_product_id());
         // Give job the package attributes
         update_post_meta($job_id, '_job_duration', $user_package->get_duration());
         update_post_meta($job_id, '_featured', $user_package->is_featured() ? 1 : 0);
         update_post_meta($job_id, '_package_id', $user_package->get_product_id());
         update_post_meta($job_id, '_user_package_id', $package_id);
         if ($package && 'listing' === $package->package_subscription_type) {
             update_post_meta($job_id, '_job_expires', '');
             // Never expire automatically
         }
         // Approve the job
         if (in_array(get_post_status($job_id), array('pending_payment', 'expired'))) {
             wc_paid_listings_approve_job_listing_with_package($job_id, get_current_user_id(), $package_id);
         }
         do_action('wcpl_process_package_for_job_listing', $package_id, $is_user_package, $job_id);
         return true;
     } elseif ($package_id) {
         $package = wc_get_product($package_id);
         // Give job the package attributes
         update_post_meta($job_id, '_job_duration', $package->get_duration());
         update_post_meta($job_id, '_featured', $package->is_featured() ? 1 : 0);
         update_post_meta($job_id, '_package_id', $package_id);
         if ('listing' === $package->package_subscription_type) {
             update_post_meta($job_id, '_job_expires', '');
             // Never expire automatically
         }
         // Add package to the cart
         WC()->cart->add_to_cart($package_id, 1, '', '', array('job_id' => $job_id));
         woocommerce_add_to_cart_message($package_id);
         // Clear cookie
         wc_setcookie('chosen_package_id', '', time() - HOUR_IN_SECONDS);
         wc_setcookie('chosen_package_is_user_package', '', time() - HOUR_IN_SECONDS);
         do_action('wcpl_process_package_for_job_listing', $package_id, $is_user_package, $job_id);
         // Redirect to checkout page
         wp_redirect(get_permalink(woocommerce_get_page_id('checkout')));
         exit;
     }
 }
コード例 #14
0
 /**
  * Destroy all session data
  */
 public function destroy_session()
 {
     // Clear cookie
     wc_setcookie($this->_cookie, '', time() - YEAR_IN_SECONDS, apply_filters('yith_ywraq_session_use_secure_cookie', false));
     // Delete session
     $session_option = '_yith_ywraq_session_' . $this->_customer_id;
     $session_expiry_option = '_yith_ywraq_session_expires_' . $this->_customer_id;
     delete_option($session_option);
     delete_option($session_expiry_option);
     // Clear data
     $this->_data = array();
     $this->_dirty = false;
     $this->_customer_id = $this->generate_customer_id();
 }
コード例 #15
0
function repair_woocommerce_ajax_add_to_cart_guest()
{
    if (defined('DOING_AJAX')) {
        wc_setcookie('woocommerce_items_in_cart', 1);
        wc_setcookie('woocommerce_cart_hash', md5(json_encode(WC()->cart->get_cart())));
        do_action('woocommerce_set_cart_cookies', true);
    }
}