Ejemplo n.º 1
0
 /**
  * Initiator method.
  *
  * @return void
  * @since 1.0.0
  */
 public function init()
 {
     if (is_user_logged_in()) {
         YITH_WCWL()->details['user_id'] = get_current_user_id();
         //check whether any products are added to wishlist, then after login add to the wishlist if not added
         $cookie = yith_getcookie('yith_wcwl_products');
         foreach ($cookie as $details) {
             YITH_WCWL()->details['add_to_wishlist'] = $details['prod_id'];
             YITH_WCWL()->details['wishlist_id'] = $details['wishlist_id'];
             YITH_WCWL()->details['quantity'] = $details['quantity'];
             YITH_WCWL()->details['user_id'] = get_current_user_id();
             $ret_val = YITH_WCWL()->add();
         }
         yith_destroycookie('yith_wcwl_products');
     }
     // update cookie from old version to new one
     $this->_update_cookies();
 }
Ejemplo n.º 2
0
 /**
  * Initiator method. Initiate properties.
  * 
  * @return void
  * @access private
  * @since 1.0.0
  */
 public function init()
 {
     global $yith_wcwl;
     $db_colors = get_option('yith_wcwl_frontend_css_colors');
     $this->colors_options = !empty($db_colors) ? maybe_unserialize($db_colors) : apply_filters('yith_wcwl_colors_options', array('add_to_wishlist' => array('background' => '#4F4F4F', 'color' => '#FFFFFF', 'border_color' => '#4F4F4F'), 'add_to_wishlist_hover' => array('background' => '#2F2F2F', 'color' => '#FFFFFF', 'border_color' => '#2F2F2F'), 'add_to_cart' => array('background' => '#4F4F4F', 'color' => '#FFFFFF', 'border_color' => '#4F4F4F'), 'add_to_cart_hover' => array('background' => '#2F2F2F', 'color' => '#FFFFFF', 'border_color' => '#2F2F2F'), 'wishlist_table' => array('background' => '#FFFFFF', 'color' => '#676868', 'border_color' => '#676868')));
     if (empty($db_colors)) {
         update_option('yith_wcwl_frontend_css_colors', maybe_serialize($this->colors_options));
     }
     $this->rules = apply_filters('yith_wcwl_colors_rules', array('add_to_wishlist' => '.woocommerce .yith-wcwl-add-button > a.button.alt', 'add_to_wishlist_hover' => '.woocommerce .yith-wcwl-add-button > a.button.alt:hover', 'add_to_cart' => '.woocommerce .wishlist_table a.add_to_cart.button.alt', 'add_to_cart_hover' => '.woocommerce .wishlist_table a.add_to_cart.button.alt:hover', 'wishlist_table' => '.wishlist_table'));
     if (is_user_logged_in()) {
         $yith_wcwl->details['user_id'] = get_current_user_id();
         //check whether any products are added to wishlist, then after login add to the wishlist if not added
         if (yith_usecookies()) {
             $cookie = yith_getcookie('yith_wcwl_products');
             foreach ($cookie as $details) {
                 $yith_wcwl->details = $details;
                 $yith_wcwl->details['user_id'] = get_current_user_id();
                 $ret_val = $yith_wcwl->add();
             }
             yith_destroycookie('yith_wcwl_products');
         } else {
             if (isset($_SESSION['yith_wcwl_products'])) {
                 foreach ($_SESSION['yith_wcwl_products'] as $details) {
                     $yith_wcwl->details = $details;
                     $yith_wcwl->details['user_id'] = get_current_user_id();
                     $ret_val = $yith_wcwl->add();
                 }
                 unset($_SESSION['yith_wcwl_products']);
             }
         }
     }
     wp_register_style('yith-wcwl-admin', YITH_WCWL_URL . 'assets/css/admin.css');
 }
 /**
  * Destroy serialize cookies, to prevent major vulnerability
  *
  * @return void
  * @since 2.0.7
  */
 private function _destroy_serialized_cookies()
 {
     $name = 'yith_wcwl_products';
     if (isset($_COOKIE[$name]) && is_serialized(stripslashes($_COOKIE[$name]))) {
         $_COOKIE[$name] = json_encode(array());
         yith_destroycookie($name);
     }
 }
Ejemplo n.º 4
0
 /**
  * Remove an entry from the wishlist.
  * 
  * @param int $id Record ID
  * @return bool
  * @since 1.0.0
  */
 public function remove($id)
 {
     global $wpdb;
     if (is_user_logged_in()) {
         $sql = "DELETE FROM `" . YITH_WCWL_TABLE . "` WHERE `ID` = " . $id . " AND `user_id` = " . $this->details['user_id'];
         if ($wpdb->query($sql)) {
             return true;
         } else {
             $this->errors[] = __('Error occurred while removing product from wishlist', 'yit');
             return false;
         }
     } elseif (yith_usecookies()) {
         $cookie = yith_getcookie('yith_wcwl_products');
         unset($cookie[$id]);
         yith_destroycookie('yith_wcwl_products');
         yith_setcookie('yith_wcwl_products', $cookie);
         return true;
     } else {
         unset($_SESSION['yith_wcwl_products'][$id]);
         return true;
     }
 }