Initial Commit N° : 001 - V.4.3.3

This commit is contained in:
2025-03-28 14:32:57 +01:00
commit 238e5d7999
809 changed files with 371149 additions and 0 deletions
+306
View File
@@ -0,0 +1,306 @@
<?php
defined('ABSPATH') or die(); // Exit if accessed directly
/**
* Nasa Advanced Free Shipping
*/
class Nasa_Advanced_Free_Shipping {
public $render = true;
protected $value = 0;
protected $_subtotal_type = 'subtotal';
protected $conditions = array();
/**
* Constructor
*/
public function __construct($conditions = array()) {
$this->conditions = $conditions;
$this->check_condition();
}
protected function check_condition() {
/**
* Check rule is subtotal
*/
foreach ($this->conditions as $condition) {
/**
* Check subtotal
*/
if (
in_array($condition['condition'], array('subtotal', 'subtotal_ex_tax')) &&
$condition['operator'] == '>=' &&
$condition['value'] &&
(!$this->value || $this->value > $condition['value'])
) {
$this->_subtotal_type = $condition['condition'];
$this->value = $condition['value'];
$this->render = true;
}
/**
* Check country
*/
if (
$condition['condition'] == 'country' &&
$condition['value']
) {
if (!$this->_check_country($condition['value'], $condition['operator'])) {
$this->value = 0;
$this->render = false;
continue;
}
}
/**
* Check State
*/
if (
$condition['condition'] == 'state' &&
$condition['value']
) {
if (!$this->_check_state($condition['value'], $condition['operator'])) {
$this->value = 0;
$this->render = false;
continue;
}
}
/**
* Check City
*/
if (
$condition['condition'] == 'city' &&
$condition['value']
) {
if (!$this->_check_city($condition['value'], $condition['operator'])) {
$this->value = 0;
$this->render = false;
continue;
}
}
/**
* Check Zipcode
*/
if (
$condition['condition'] == 'zipcode' &&
$condition['value']
) {
if (!$this->_check_zipcode($condition['value'], $condition['operator'])) {
$this->value = 0;
$this->render = false;
continue;
}
}
/**
* Check weight
*/
if (
$condition['condition'] == 'weight' &&
$condition['value']
) {
if (!$this->_check_weight($condition['value'], $condition['operator'])) {
$this->value = 0;
$this->render = false;
continue;
}
}
}
if (!$this->value) {
$this->render = false;
}
}
/**
* Check Customer Contry
*
* @param type $country
* @param type $operator
* @return bool
*/
protected function _check_country($country = '', $operator = '==') {
$user_country = WC()->customer->get_shipping_country();
$match = false;
if ('==' == $operator) :
$match = ($user_country == $country);
elseif ('!=' == $operator) :
$match = ($user_country != $country);
endif;
return $match;
}
/**
* Check Customer State
*
* @param type $state
* @param type $operator
* @return bool
*/
protected function _check_state($state = '', $operator = '==') {
$user_state = WC()->customer->get_shipping_state();
$match = false;
if ('==' == $operator) :
$match = ($user_state == $state);
elseif ('!=' == $operator) :
$match = ($user_state != $state);
endif;
return $match;
}
/**
* Check Customer City
*
* @param type $city
* @param type $operator
* @return bool
*/
protected function _check_city($city = '', $operator = '==') {
$user_city = WC()->customer->get_shipping_city();
$match = false;
if ('==' == $operator) :
$match = ($user_city == $city);
elseif ('!=' == $operator) :
$match = ($user_city != $city);
endif;
return $match;
}
/**
* Check Customer zipcode / postcode
*
* @param type $zipcode
* @param type $operator
* @return bool
*/
protected function _check_zipcode($zipcode = '', $operator = '==') {
$user_zipcode = WC()->customer->get_shipping_postcode();
$match = false;
if ('==' == $operator) :
$match = ($user_zipcode == $zipcode);
elseif ('!=' == $operator) :
$match = ($user_zipcode != $zipcode);
endif;
return $match;
}
/**
* Check total weight
*
* @param type $weight
* @param type $operator
* @return bool
*/
protected function _check_weight($weight = '', $operator = '<=') {
$tt_weight = WC()->cart->get_cart_contents_weight();
$match = false;
if ('==' == $operator) :
$match = ($tt_weight == $weight);
elseif ('!=' == $operator) :
$match = ($tt_weight != $weight);
elseif ('>=' == $operator) :
$match = ($tt_weight >= $weight);
elseif ('<=' == $operator) :
$match = ($tt_weight <= $weight);
endif;
return $match;
}
/**
* Output HTML
*
* @return string
*/
public function output_html() {
$content = '';
$style = '';
$cookieName = 'nasa_curent_per_shipping';
if(isset($_COOKIE[$cookieName])) {
$cookieValue = $_COOKIE[$cookieName];
$style .= ' style="width: ' . $cookieValue. '%;"';
}
if ($this->value && $this->render) {
if ($this->_subtotal_type == 'subtotal_ex_tax') {
$subtotal_cart = method_exists(WC()->cart, 'get_subtotal') ? WC()->cart->get_subtotal() : WC()->cart->subtotal_ex_tax;
} else {
$subtotal_cart = WC()->cart->subtotal;
}
$spend = 0;
$content_cond = '';
$content_desc = '';
/**
* Check free shipping
*/
if ($subtotal_cart < $this->value) {
$spend = $this->value - $subtotal_cart;
$per = intval(($subtotal_cart/$this->value)*100);
$allowed_html = array(
'strong' => array(),
'a' => array(
'class' => array(),
'href' => array(),
'title' => array()
),
'span' => array(
'class' => array()
),
'br' => array()
);
$content_desc .= '<div class="nasa-total-condition-desc text-center">' .
sprintf(
wp_kses(__('Spend %s more to reach <strong>FREE SHIPPING!</strong> <a class="continue-cart hide-in-cart-sidebar" href="%s" title="Continue Shopping">Continue Shopping</a>', 'elessi-theme'), $allowed_html),
wc_price($spend),
esc_url(get_permalink(wc_get_page_id('shop')))
) .
'</div>';
}
/**
* Congratulations! You've got free shipping!
*/
else {
$per = 100;
$content_desc .= '<div class="nasa-total-condition-desc nasa-flex jc text-center">';
$content_desc .= '<svg class="ns-check-svg text-success margin-right-5 rtl-margin-right-0 rtl-margin-left-5" width="20" height="20" viewBox="0 0 32 32"><path d="M16 2.672c-7.361 0-13.328 5.967-13.328 13.328s5.968 13.328 13.328 13.328c7.361 0 13.328-5.967 13.328-13.328s-5.967-13.328-13.328-13.328zM16 28.262c-6.761 0-12.262-5.501-12.262-12.262s5.5-12.262 12.262-12.262c6.761 0 12.262 5.501 12.262 12.262s-5.5 12.262-12.262 12.262z" fill="currentColor" /><path d="M22.667 11.241l-8.559 8.299-2.998-2.998c-0.312-0.312-0.818-0.312-1.131 0s-0.312 0.818 0 1.131l3.555 3.555c0.156 0.156 0.361 0.234 0.565 0.234 0.2 0 0.401-0.075 0.556-0.225l9.124-8.848c0.317-0.308 0.325-0.814 0.018-1.131-0.309-0.318-0.814-0.325-1.131-0.018z" fill="currentColor" /></svg>';
$content_desc .= esc_html__("Congratulations! You've got free shipping.", 'elessi-theme');
$content_desc .= '</div>';
}
$class_cond = 'nasa-total-condition-wrap';
$content_cond .= '<div class="nasa-total-condition" data-per="' . $per . '">' .
'<div class="nasa-subtotal-condition primary-bg nasa-relative"' . $style. '>' .
'<span class="nasa-total-number primary-border text-center nasa-flex jc">' . $per . '%</span>' .
'</div>' .
'</div>';
$content .= '<div class="' . $class_cond . '">';
$content .= $content_cond;
$content .= '</div>';
$content .= $content_desc;
}
return $content;
}
}
+117
View File
@@ -0,0 +1,117 @@
<?php
defined('ABSPATH') or die(); // Exit if accessed directly
/**
* Captcha image
*/
class Nasa_Captcha {
private $img_width = 120;
private $img_height = 30;
private $font_path = ELESSI_THEME_PATH . '/assets/captcha-fonts'; // Path file text
private $fonts = array();
private $font_size = 15;
private $char_set = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
private $char_length = 5;
private $char_color = "#880000,#008800,#000088,#888800,#880088,#008888,#000000";
private $char_colors = array();
private $line_count = 10;
private $line_color = "#DD6666,#66DD66,#6666DD,#DDDD66,#DD66DD,#66DDDD,#666666";
private $line_colors = array();
private $bg_color = '#FFFFFF';
public function __construct($length = 5, $width = 120, $height = 30) {
$this->char_length = $length;
$this->img_width = $width;
$this->img_height = $height;
}
// Init Setting
// return code and Show Img
public function get_and_show_image($override = array()) {
/**
* Check missing Grab function list
* GD Library
*/
if (!function_exists('imagecreatetruecolor')) {
return null;
}
// Override default config
if (is_array($override)) {
foreach ($override as $key => $value) {
if (isset($this->$key)) {
$this->$key = $value;
}
}
}
// Create list colors to Array
$this->line_colors = preg_split("/,\s*?/", $this->line_color);
$this->char_colors = preg_split("/,\s*?/", $this->char_color);
// Get fonts font_path
$this->fonts = $this->collect_files($this->font_path, "ttf");
// Init IMG
$img = imagecreatetruecolor($this->img_width, $this->img_height);
imagefilledrectangle($img, 0, 0, $this->img_width - 1, $this->img_height - 1, $this->gd_color($this->bg_color));
// Draw random
for ($i = 0; $i < $this->line_count; $i++) {
imageline($img, rand(0, $this->img_width - 1), rand(0, $this->img_height - 1), rand(0, $this->img_width - 1), rand(0, $this->img_height - 1), $this->gd_color($this->line_colors[rand(0, count($this->line_colors) - 1)])
);
}
// Draw code
$code = "";
$y = intval(($this->img_height / 2) + ($this->font_size / 2));
for ($i = 0; $i < $this->char_length; $i++) {
$color = $this->gd_color($this->char_colors[rand(0, count($this->char_colors) - 1)]);
$angle = rand(-30, 30);
$char = substr($this->char_set, rand(0, strlen($this->char_set) - 1), 1);
$sel_font = $this->fonts[rand(0, count($this->fonts) - 1)];
$font = $this->font_path . "/" . $sel_font;
$x = intval(($this->img_width / $this->char_length) * $i + ($this->font_size / 2));
$code .= $char;
imagettftext($img, $this->font_size, $angle, $x, $y, $color, $font, $char);
}
// Show image
header('content-type: image/jpg');
imagejpeg($img);
imagedestroy($img);
return strtolower($code);
}
// Change color
protected function gd_color($html_color) {
$rgb = array();
return preg_match('/^#?([\dA-F]{6})$/i', $html_color, $rgb) ? hexdec($rgb[1]) : false;
}
// get list files (ext)
protected function collect_files($dir, $ext) {
if (false !== ($dir = opendir($dir))) {
$files = array();
while (false !== ($file = readdir($dir))) {
if (preg_match("/\\.$ext\$/i", $file)) {
$files[] = $file;
}
}
return $files;
}
return false;
}
}
File diff suppressed because it is too large Load Diff
+315
View File
@@ -0,0 +1,315 @@
<?php
defined('ABSPATH') or die(); // Exit if accessed directly
/**
* Add action dokan
*/
add_action('init', 'elessi_add_action_dokan');
if (!function_exists('elessi_add_action_dokan')) :
function elessi_add_action_dokan() {
global $nasa_opt;
add_action('woocommerce_after_shop_loop_item_title', 'elessi_dokan_loop_sold_by');
add_action('woocommerce_single_product_summary', 'elessi_dokan_loop_sold_by', 20);
// Hide Uncategorized
if (!isset($nasa_opt['show_uncategorized']) || !$nasa_opt['show_uncategorized']) {
add_filter('dokan_category_widget', 'elessi_hide_uncategorized');
}
add_filter('woocommerce_get_breadcrumb', 'elessi_dokan_get_breadcrumb', 9999);
}
endif;
/**
* Since 5.1.8
*
* Fix Breadcrumb Dokan Store
*/
if (!function_exists('elessi_dokan_loop_sold_by')) :
function elessi_dokan_get_breadcrumb($crumbs) {
if (!dokan_is_store_page()) {
return $crumbs;
}
if (function_exists('yoast_breadcrumb') && \WPSEO_Options::get('breadcrumbs-enable')) {
unset($crumbs);
return;
}
$custom_store_url = dokan_get_option('custom_store_url', 'dokan_general', 'store');
$author = get_query_var($custom_store_url);
$seller_info = get_user_by('slug', $author);
if (!$seller_info) {
return;
}
$store_user = dokan()->vendor->get($seller_info);
$shop_name = $store_user->get_shop_name();
$crumbs[2] = [$shop_name, dokan_get_store_url($seller_info->data->ID)];
return $crumbs;
}
endif;
/**
* Compatible with DOKAN plugin
*
* sold-by in loop
*/
if (!function_exists('elessi_dokan_loop_sold_by')) :
function elessi_dokan_loop_sold_by() {
global $post, $nasa_dokan_vendors;
if (!$post) {
return;
}
if (!isset($nasa_dokan_vendors)) {
$nasa_dokan_vendors = array();
}
if (!isset($nasa_dokan_vendors[$post->post_author])) {
$author = get_user_by('id', $post->post_author);
$store_info = dokan_get_store_info($author->ID);
if (!empty($store_info['store_name'])) {
$nasa_dokan_vendors[$post->post_author]['name'] = $store_info['store_name'];
$nasa_dokan_vendors[$post->post_author]['url'] = dokan_get_store_url($author->ID);
} else {
$nasa_dokan_vendors[$post->post_author] = null;
}
$GLOBALS['nasa_dokan_vendors'] = $nasa_dokan_vendors;
}
if (isset($nasa_dokan_vendors[$post->post_author]) && $nasa_dokan_vendors[$post->post_author]) {
echo '<span class="nasa-dokan-sold_by_in_loop">' .
esc_html__('Sold By: ', 'elessi-theme') .
'<a ' .
'href="' . esc_url($nasa_dokan_vendors[$post->post_author]['url']) . '" ' .
'class="nasa-dokan-sold_by_href" ' .
'title="' . esc_attr($nasa_dokan_vendors[$post->post_author]['name']) . '">' .
$nasa_dokan_vendors[$post->post_author]['name'] .
'</a>' .
'</span>';
}
}
endif;
/**
* dokan_enqueue_style
*/
add_action('nasa_before_store_dokan', 'elessi_dokan_enqueue_style');
if (!function_exists('elessi_dokan_enqueue_style')) :
function elessi_dokan_enqueue_style() {
global $nasa_opt;
$in_mobile = isset($nasa_opt['nasa_in_mobile']) && $nasa_opt['nasa_in_mobile'] ? true : false;
$themeVersion = isset($nasa_opt['css_theme_version']) && $nasa_opt['css_theme_version'] ? apply_filters('nasa_version_assets', NASA_VERSION) : null;
$prefix = elessi_prefix_theme();
if (!$in_mobile) {
wp_enqueue_style($prefix . '-style-products-list', ELESSI_THEME_URI . '/assets/css/style-products-list.css', array(), $themeVersion);
}
}
endif;
/**
* Change view layout
*/
add_action('dokan_store_profile_frame_after', 'elessi_dokan_change_view_store', 15);
if (!function_exists('elessi_dokan_change_view_store')) :
function elessi_dokan_change_view_store() {
elessi_nasa_change_view('no');
}
endif;
/**
* Class Nasa_Stores
* Output: Shortcode nasa-dokan-stores
*/
if (class_exists('WeDevs\Dokan\Abstracts\DokanShortcode')) :
class Nasa_Stores extends WeDevs\Dokan\Abstracts\DokanShortcode {
protected $shortcode = 'nasa-dokan-stores';
/**
* Displays the store lists
*
* @since 2.4
*
* @param array $atts
*
* @return string
*/
public function render_shortcode($atts) {
$defaults = array(
'per_page' => 10,
'search' => 'yes',
'per_row' => '3',
'featured' => 'no',
'category' => '',
'order' => '',
'orderby' => '',
'store_id' => '',
'with_products_only' => '',
'style' => 'grid-1'
);
/**
* Filter return the number of store listing number per page.
*
* @since 2.2
*
* @param array
*/
$attr = shortcode_atts(apply_filters('dokan_store_listing_per_page', $defaults), $atts);
$paged = (int) is_front_page() ? max(1, get_query_var('page')) : max(1, get_query_var('paged'));
$limit = $attr['per_page'];
$offset = ($paged - 1) * $limit;
$seller_args = array(
'number' => $limit,
'offset' => $offset,
'order' => 'DESC',
);
$_get_data = wp_unslash($_GET);
// if search is enabled, perform a search
if ('yes' === $attr['search']) {
if (!empty($_get_data['dokan_seller_search'])) {
$seller_args['meta_query'] = array(
array(
'key' => 'dokan_store_name',
'value' => wc_clean($_get_data['dokan_seller_search']),
'compare' => 'LIKE',
),
);
}
}
if ('yes' === $attr['featured']) {
$seller_args['featured'] = 'yes';
}
if (!empty($attr['category'])) {
$seller_args['store_category_query'][] = array(
'taxonomy' => 'store_category',
'field' => 'slug',
'terms' => explode(',', $attr['category']),
);
}
if (!empty($attr['order'])) {
$seller_args['order'] = $attr['order'];
}
if (!empty($attr['orderby'])) {
$seller_args['orderby'] = $attr['orderby'];
}
if (!empty($attr['with_products_only']) && 'yes' === $attr['with_products_only']) {
$seller_args['has_published_posts'] = ['product'];
}
if (!empty($attr['store_id'])) {
$seller_args['include'] = explode(',', $attr['store_id']);
}
$sellers = dokan_get_sellers(apply_filters('dokan_seller_listing_args', $seller_args, $_GET));
if (!in_array($attr['style'], array('grid-1', 'grid-2', 'list-1', 'list-2', 'list-3'))) {
$attr['style'] = 'grid-1';
}
/**
* Filter for store listing args
*
* @since 2.4.9
*/
$template_args = apply_filters(
'dokan_store_list_args', array(
'sellers' => $sellers,
'limit' => $limit,
'offset' => $offset,
'paged' => $paged,
'image_size' => 'full',
'search' => $attr['search'],
'per_row' => in_array($attr['per_row'], array('2', '3')) ? $attr['per_row'] : 2,
'layout' => $attr['style']
)
);
ob_start();
dokan_get_template_part('nasa-store-lists', false, $template_args);
$content = ob_get_clean();
return apply_filters('nasa_dokan_seller_listing', $content, $attr);
}
}
endif;
/**
* Register Shortcode nasa-dokan-stores
*
*/
add_filter('dokan_shortcodes', 'elessi_dokan_sc_nasa_stores');
if (!function_exists('elessi_dokan_sc_nasa_stores')) :
function elessi_dokan_sc_nasa_stores($shortcodes) {
$shortcodes['nasa-dokan-stores'] = new Nasa_Stores();
return $shortcodes;
}
endif;
/**
* Get Products from seller
*/
if (!function_exists('elessi_dokan_products_from_seller')) :
function elessi_dokan_products_from_seller($seller_id = 0, $posts_per_page = 5) {
return new WP_Query(array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => (int) $posts_per_page,
'orderby' => apply_filters('nasa_order_by_dokan_product_from_seller', 'rand'),
'author' => (int) $seller_id
));
}
endif;
/**
* Filter Store Listing Page
*/
add_filter('dokan_is_store_listing', 'elessi_is_store_listing', 10, 2);
if (!function_exists('elessi_is_store_listing')) :
function elessi_is_store_listing($found, $page_id) {
if (!$found) {
$post = get_post($page_id);
if ($post && false !== strpos($post->post_content, '[nasa-dokan-stores')) {
$found = true;
}
}
return $found;
}
endif;
File diff suppressed because it is too large Load Diff
+240
View File
@@ -0,0 +1,240 @@
<?php
defined('ABSPATH') or die(); // Exit if accessed directly
/**
* Get term description
*
* Outdate from 2.1.4
*/
if (!function_exists('elessi_term_description')) :
function elessi_term_description($term_id, $type_taxonomy) {
_deprecated_function(__FUNCTION__, '2.1.4', null);
if (!NASA_WOO_ACTIVED) {
return '';
}
if ((int) $term_id < 1) {
$shop_page = get_post(wc_get_page_id('shop'));
$desc = $shop_page ? wc_format_content($shop_page->post_content) : '';
} else {
$term = get_term($term_id, $type_taxonomy);
$desc = isset($term->description) ? $term->description : '';
}
return trim($desc) != '' ? '<div class="page-description">' . do_shortcode($desc) . '</div>' : '';
}
endif;
/**
* Get cat header content
*
* Outdate from 2.1.4
*/
if (!function_exists('elessi_get_cat_header')):
function elessi_get_cat_header($catId = null) {
_deprecated_function(__FUNCTION__, '2.1.4', null);
global $nasa_opt;
if (isset($nasa_opt['enable_cat_header']) && $nasa_opt['enable_cat_header'] != '1') {
return '';
}
$content = '<div class="cat-header nasa-cat-header padding-top-20">';
$do_content = '';
if ((int) $catId > 0) {
$shortcode = function_exists('get_term_meta') ? get_term_meta($catId, 'cat_header', false) : get_woocommerce_term_meta($catId, 'cat_header', false);
$do_content = isset($shortcode[0]) ? do_shortcode($shortcode[0]) : '';
}
if (trim($do_content) === '') {
if (isset($nasa_opt['cat_header']) && $nasa_opt['cat_header'] != '') {
$do_content = do_shortcode($nasa_opt['cat_header']);
}
}
if (trim($do_content) === '') {
return '';
}
$content .= $do_content . '</div>';
return $content;
}
endif;
/**
* Deprecated
*
* Language Flags
*
* Not use from 4.6.2
*/
if (!function_exists('elessi_language_flages')) :
function elessi_language_flages() {
_deprecated_function(__FUNCTION__, '4.6.2', 'elessi_multi_languages');
global $nasa_opt;
if (!isset($nasa_opt['switch_lang']) || $nasa_opt['switch_lang'] != 1) {
return;
}
$language_output = '<div class="nasa-select-languages">';
$mainLang = '';
$selectLang = '<ul class="nasa-list-languages">';
if (function_exists('icl_get_languages')) {
$current = defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : get_option('WPLANG');
$languages = icl_get_languages('skip_missing=0&orderby=code');
if (!empty($languages)) {
foreach ($languages as $lang) {
/**
* Current Language
*/
if ($current == $lang['language_code']) {
$mainLang .= '<a href="javascript:void(0);" class="nasa-current-lang" rel="nofollow">';
if (isset($lang['country_flag_url'])) {
$mainLang .= '<img src="' . esc_url($lang['country_flag_url']) . '" alt="' . esc_attr($lang['native_name']) . '" />';
}
$mainLang .= $lang['native_name'];
$mainLang .= '</a>';
}
/**
* Select Languages
*/
else {
$selectLang .= '<li class="nasa-item-lang"><a href="' . esc_url($lang['url']) . '" title="' . esc_attr($lang['native_name']) . '" rel="nofollow">';
if (isset($lang['country_flag_url'])) {
$selectLang .= '<img src="' . esc_url($lang['country_flag_url']) . '" alt="' . esc_attr($lang['native_name']) . '" />';
}
$selectLang .= $lang['native_name'];
$selectLang .= '</a></li>';
}
}
}
}
/**
* have not installs WPML
*/
else {
$mainLang .= '<a href="javascript:void(0);" class="nasa-current-lang" rel="nofollow">';
// $mainLang .= '<img src="' . esc_url(ELESSI_THEME_URI . '/assets/images/en.png') . '" alt="English" />';
$mainLang .= 'Requires WPML';
$mainLang .= '</a>';
/**
* Select Languages
*/
// English
$selectLang .= '<li class="nasa-item-lang"><a href="javascript:void(0);" title="English">';
// $selectLang .= '<img src="' . esc_url(ELESSI_THEME_URI . '/assets/images/en.png') . '" alt="English" />';
$selectLang .= 'English';
$selectLang .= '</a></li>';
// German
$selectLang .= '<li class="nasa-item-lang"><a href="javascript:void(0);" title="Deutsch">';
// $selectLang .= '<img src="' . esc_url(ELESSI_THEME_URI . '/assets/images/de.png') . '" alt="Deutsch" />';
$selectLang .= 'Deutsch';
$selectLang .= '</a></li>';
// French
$selectLang .= '<li class="nasa-item-lang"><a href="javascript:void(0);" title="Français">';
// $selectLang .= '<img src="' . esc_url(ELESSI_THEME_URI . '/assets/images/fr.png') . '" alt="Français" />';
$selectLang .= 'Français';
$selectLang .= '</a></li>';
}
$selectLang .= '</ul>';
$language_output .= $mainLang . $selectLang . '</div>';
echo '<ul class="header-switch-languages left rtl-right desktop-margin-right-30 rtl-desktop-margin-right-0 rtl-desktop-margin-left-30"><li>' . $language_output . '</li></ul>';
}
endif;
/**
* Change elessi_product_video_btn_function => elessi_product_video_btn
*/
if (function_exists('elessi_product_video_btn_function')) {
remove_action('nasa_single_buttons', 'elessi_product_video_btn', 25);
add_action('nasa_single_buttons', 'elessi_product_video_btn_function', 25);
}
/**
* Change elessi_footer_layout_style_function => elessi_footer_layout
*/
if (function_exists('elessi_footer_layout_style_function')) {
remove_action('nasa_footer_layout_style', 'elessi_footer_output');
add_action('nasa_footer_layout_style', 'elessi_footer_layout_style_function');
}
/**
* Change elessi_get_custom_field_value => elessi_get_product_meta_value
*
* Not use from 4.6.2
*/
if (!function_exists('elessi_get_custom_field_value')) :
function elessi_get_custom_field_value($post_id, $field_id) {
_deprecated_function(__FUNCTION__, '4.6.2', 'elessi_get_product_meta_value');
return elessi_get_product_meta_value($post_id, $field_id);
}
endif;
/**
* Add to cart button
*
* Not use from 4.6.2
*/
if (!function_exists('elessi_add_to_cart_btn')):
function elessi_add_to_cart_btn() {
if (function_exists('woocommerce_template_loop_add_to_cart')) {
_deprecated_function(__FUNCTION__, '4.6.2', 'woocommerce_template_loop_add_to_cart');
woocommerce_template_loop_add_to_cart();
}
}
endif;
/**
* Add to cart in list
*
* Not use from 4.6.2
*/
if (!function_exists('elessi_add_to_cart_in_list')) :
function elessi_add_to_cart_in_list() {
global $nasa_opt;
if (!isset($nasa_opt['loop_add_to_cart']) || $nasa_opt['loop_add_to_cart']) {
_deprecated_function(__FUNCTION__, '4.6.2', 'woocommerce_template_loop_add_to_cart');
woocommerce_template_loop_add_to_cart();
}
}
endif;
/**
* Mini Cart considered a Cart page if the incoming call is AJAX
*
* Since 5.3.9
* Not use from 6.1.7
*/
if (!function_exists('elessi_mini_cart_as_cart_page')) :
function elessi_mini_cart_as_cart_page() {
if (defined('DOING_AJAX') && DOING_AJAX) :
wc_maybe_define_constant('WOOCOMMERCE_CART', true);
endif;
}
endif;
+233
View File
@@ -0,0 +1,233 @@
<?php
defined('ABSPATH') or die(); // Exit if accessed directly
/**
*
* @param type $font_families
* @param type $font_set
* @return string The cleaned URL.
*/
if (!function_exists('elessi_google_fonts_url')) :
function elessi_google_fonts_url($font_families = array(), $font_set = array()) {
$query_args = array();
if ($font_families) {
$query_args['family'] = implode('|', $font_families);
}
if ($font_set) {
$query_args['subset'] = implode(',', $font_set);
}
if (empty($query_args)) {
return false;
}
$query_args['display'] = apply_filters('nasa_google_font_display', 'swap');
return add_query_arg($query_args, 'https://fonts.googleapis.com/css');
}
endif;
/**
* Register font
*/
add_action('wp_enqueue_scripts', 'elessi_register_fonts');
if (!function_exists('elessi_register_fonts')) :
function elessi_register_fonts() {
/**
* Override page | Category
*/
global $wp_query, $nasa_opt;
$object_id = $wp_query->get_queried_object_id();
$type_font_select = '';
$custom_font = '';
$type_headings = '';
$type_texts = '';
$type_nav = '';
$type_banner = '';
$type_price = '';
if ('page' === get_post_type() && $object_id) {
$type_font_select = get_post_meta($object_id, '_nasa_type_font_select', true);
if ($type_font_select == 'google') {
$type_headings = get_post_meta($object_id, '_nasa_type_headings', true);
$type_texts = get_post_meta($object_id, '_nasa_type_texts', true);
$type_nav = get_post_meta($object_id, '_nasa_type_nav', true);
$type_banner = get_post_meta($object_id, '_nasa_type_banner', true);
$type_price = get_post_meta($object_id, '_nasa_type_price', true);
}
if ($type_font_select == 'custom') {
$custom_font = get_post_meta($object_id, '_nasa_custom_font', true);
}
}
/**
* Override primary color for root category product
*/
else {
$root_cat_id = elessi_get_root_term_id();
if ($root_cat_id) {
$type_font_select = get_term_meta($root_cat_id, 'type_font', true);
if ($type_font_select == 'google') {
$type_headings = get_term_meta($root_cat_id, 'headings_font', true);
$type_texts = get_term_meta($root_cat_id, 'texts_font', true);
$type_nav = get_term_meta($root_cat_id, 'nav_font', true);
$type_banner = get_term_meta($root_cat_id, 'banner_font', true);
$type_price = get_term_meta($root_cat_id, 'price_font', true);
}
if ($type_font_select == 'custom') {
$custom_font = get_term_meta($root_cat_id, 'custom_font', true);
}
}
}
/**
* Global Font register in NasaTheme Options
*/
if (!$type_font_select) {
$type_font_select = isset($nasa_opt['type_font_select']) ? $nasa_opt['type_font_select'] : '';
$key_rtl = NASA_RTL ? '_rtl' : '';
$custom_font = isset($nasa_opt['custom_font' . $key_rtl]) ? $nasa_opt['custom_font' . $key_rtl] : '';
$type_headings = isset($nasa_opt['type_headings' . $key_rtl]) ? $nasa_opt['type_headings' . $key_rtl] : '';
$type_texts = isset($nasa_opt['type_texts' . $key_rtl]) ? $nasa_opt['type_texts' . $key_rtl] : '';
$type_nav = isset($nasa_opt['type_nav' . $key_rtl]) ? $nasa_opt['type_nav' . $key_rtl] : '';
$type_banner = isset($nasa_opt['type_banner' . $key_rtl]) ? $nasa_opt['type_banner' . $key_rtl] : '';
$type_price = isset($nasa_opt['type_price' . $key_rtl]) ? $nasa_opt['type_price' . $key_rtl] : '';
}
$fontSets = '';
/**
* Select Font custom use load site
*/
if ($type_font_select == 'custom' && $custom_font) {
global $nasa_upload_dir;
if (!isset($nasa_upload_dir)) {
$nasa_upload_dir = wp_upload_dir();
$GLOBALS['nasa_upload_dir'] = $nasa_upload_dir;
}
if (is_file($nasa_upload_dir['basedir'] . '/nasa-custom-fonts/' . $custom_font . '/' . $custom_font . '.css')) {
$fontSets = elessi_remove_protocol($nasa_upload_dir['baseurl']) . '/nasa-custom-fonts/' . $custom_font . '/' . $custom_font . '.css';
}
}
/**
* Select Google Font use load site
*/
elseif ($type_font_select == 'google') {
$default_fonts = array(
"Open Sans",
"Helvetica",
"Arial",
"Sans-serif"
);
$font_not_g = array(
'Arial',
'Trebuchet',
'Trebuchet Ms',
'Times New Roman',
'Tahoma',
'Helvetica'
);
$googlefonts = array();
if ($type_headings && !in_array($type_headings, $googlefonts)) {
$googlefonts[] = $type_headings;
}
if ($type_texts && !in_array($type_texts, $googlefonts)) {
$googlefonts[] = $type_texts;
}
if ($type_nav && !in_array($type_nav, $googlefonts)) {
$googlefonts[] = $type_nav;
}
if ($type_banner && !in_array($type_banner, $googlefonts)) {
$googlefonts[] = $type_banner;
}
if ($type_price && !in_array($type_price, $googlefonts)) {
$googlefonts[] = $type_price;
}
$rtl = apply_filters('nasa_google_fonts_rtl', NASA_RTL);
if ($rtl) {
$type_headings_rtl = isset($nasa_opt['type_headings_rtl']) ? $nasa_opt['type_headings_rtl'] : '';
$type_texts_rtl = isset($nasa_opt['type_texts_rtl']) ? $nasa_opt['type_texts_rtl'] : '';
$type_nav_rtl = isset($nasa_opt['type_nav_rtl']) ? $nasa_opt['type_nav_rtl'] : '';
$type_banner_rtl = isset($nasa_opt['type_banner_rtl']) ? $nasa_opt['type_banner_rtl'] : '';
$type_price_rtl = isset($nasa_opt['type_price_rtl']) ? $nasa_opt['type_price_rtl'] : '';
if ($type_headings_rtl && !in_array($type_headings_rtl, $googlefonts)) {
$googlefonts[] = $type_headings_rtl;
}
if ($type_texts_rtl && !in_array($type_texts_rtl, $googlefonts)) {
$googlefonts[] = $type_texts_rtl;
}
if ($type_nav_rtl && !in_array($type_nav_rtl, $googlefonts)) {
$googlefonts[] = $type_nav_rtl;
}
if ($type_banner_rtl && !in_array($type_banner_rtl, $googlefonts)) {
$googlefonts[] = $type_banner_rtl;
}
if ($type_price_rtl && !in_array($type_price_rtl, $googlefonts)) {
$googlefonts[] = $type_price_rtl;
}
}
$nasa_font_family = array();
$nasa_font_set = array();
if (!empty($nasa_opt['type_subset'])) {
foreach ($nasa_opt['type_subset'] as $key => $val) {
if ($val && !in_array($key, $nasa_font_set)) {
$nasa_font_set[] = $key;
}
}
}
if ($googlefonts) {
$font_weight = apply_filters('nasa_google_font_weight', ':300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic');
foreach ($googlefonts as $googlefont) {
if (in_array($googlefont, $font_not_g)) {
continue;
}
if (!in_array($googlefont, $default_fonts)) {
$default_fonts[] = $googlefont;
$nasa_font_family[] = $googlefont . $font_weight;
}
}
}
if (!empty($nasa_font_family)) {
$fontSets = elessi_google_fonts_url($nasa_font_family, $nasa_font_set);
}
}
if ($fontSets) {
wp_enqueue_style('nasa-fonts', $fontSets);
}
}
endif;
+455
View File
@@ -0,0 +1,455 @@
<?php
defined('ABSPATH') or die(); // Exit if accessed directly
/**
* Register Ajax Actions
*/
if (!function_exists('elessi_ajax_actions')) :
function elessi_ajax_actions($ajax_actions = array()) {
$ajax_actions[] = 'nasa_update_wishlist';
$ajax_actions[] = 'nasa_remove_from_wishlist';
$ajax_actions[] = 'live_search_products';
return $ajax_actions;
}
endif;
/**
* Map short code for ajax
*/
if (!function_exists('elessi_init_map_shortcode')) :
function elessi_init_map_shortcode() {
if (class_exists('WPBMap')) {
WPBMap::addAllMappedShortcodes();
}
}
endif;
/**
* Update Wishlist
* Yith Wishlist
*/
add_action('wp_ajax_nasa_update_wishlist', 'elessi_update_wishlist');
add_action('wp_ajax_nopriv_nasa_update_wishlist', 'elessi_update_wishlist');
if (!function_exists('elessi_update_wishlist')) :
function elessi_update_wishlist(){
global $nasa_opt;
$json = array(
'list' => '',
'count' => 0
);
$json['list'] = elessi_mini_wishlist_sidebar(true);
$json['status_add'] = 'true';
$count = function_exists('yith_wcwl_count_products') ? yith_wcwl_count_products() : 0;
if (!isset($nasa_opt['compact_number']) || $nasa_opt['compact_number']) {
$count = (int) $count > 9 ? '9+' : (int) $count;
}
$json['count'] = apply_filters('nasa_mini_wishlist_total_items', $count);
// if (NASA_WISHLIST_NEW_VER && isset($_REQUEST['added']) && $_REQUEST['added']) {
// $json['mess'] = '<div id="yith-wcwl-message">' . esc_html__('Product Added!', 'elessi-theme') . '</div>';
// }
die(json_encode($json));
}
endif;
/**
* Remove From Wishlist
* Yith Wishlist
*/
add_action('wp_ajax_nasa_remove_from_wishlist', 'elessi_remove_from_wishlist');
add_action('wp_ajax_nopriv_nasa_remove_from_wishlist', 'elessi_remove_from_wishlist');
if (!function_exists('elessi_remove_from_wishlist')) :
function elessi_remove_from_wishlist(){
global $nasa_opt;
$json = array(
'error' => '1',
'list' => '',
'count' => 0,
'mess' => ''
);
if (!NASA_WISHLIST_ENABLE) {
die(json_encode($json));
}
$detail = array();
$detail['remove_from_wishlist'] = isset($_REQUEST['remove_from_wishlist']) ? (int) $_REQUEST['remove_from_wishlist'] : 0;
$detail['wishlist_id'] = isset($_REQUEST['wishlist_id']) ? (int) $_REQUEST['wishlist_id'] : 0;
$detail['pagination'] = isset($_REQUEST['pagination']) ? (int) $_REQUEST['pagination'] : 'no';
$detail['per_page'] = isset($_REQUEST['per_page']) ? (int) $_REQUEST['per_page'] : 5;
$detail['current_page'] = isset($_REQUEST['current_page']) ? (int) $_REQUEST['current_page'] : 1;
$detail['user_id'] = NASA_CORE_USER_LOGGED ? get_current_user_id() : false;
$mess_success = '<div id="yith-wcwl-message">' . esc_html__('Product successfully removed!', 'elessi-theme') . '</div>';
if (!NASA_WISHLIST_NEW_VER) {
$nasa_wishlist = new YITH_WCWL($detail);
$json['error'] = elessi_remove_wishlist_item($nasa_wishlist, true) ? '0' : '1';
if ($json['error'] == '0') {
$json['list'] = elessi_mini_wishlist_sidebar(true);
$count = yith_wcwl_count_products();
if (!isset($nasa_opt['compact_number']) || $nasa_opt['compact_number']) {
$count = (int) $count > 9 ? '9+' : (int) $count;
}
$json['count'] = apply_filters('nasa_mini_compare_total_items', $count);
$json['mess'] = $mess_success;
}
} else {
try{
YITH_WCWL()->remove($detail);
$json['list'] = elessi_mini_wishlist_sidebar(true);
$count = yith_wcwl_count_products();
if (!isset($nasa_opt['compact_number']) || $nasa_opt['compact_number']) {
$count = (int) $count > 9 ? '9+' : (int) $count;
}
$json['count'] = apply_filters('nasa_mini_compare_total_items', $count);
$json['mess'] = $mess_success;
$json['error'] = '0';
} catch(Exception $e) {
$json['mess'] = $e->getMessage();
}
}
die(json_encode($json));
}
endif;
/**
* Remove Wishlist item
* Yith Wishlist
*/
if (!function_exists('elessi_remove_wishlist_item')) :
function elessi_remove_wishlist_item($nasa_wishlist, $remove_force) {
if (!function_exists('yith_getcookie')) {
return false;
}
if (get_option('yith_wcwl_remove_after_add_to_cart') == 'yes' || $remove_force) {
if (!$nasa_wishlist->details['user_id']){
$wishlist = yith_getcookie('yith_wcwl_products');
foreach ($wishlist as $key => $item){
if ($item['prod_id'] == $nasa_wishlist->details['remove_from_wishlist']){
unset($wishlist[$key]);
}
}
yith_setcookie('yith_wcwl_products', $wishlist);
return true;
}
return $nasa_wishlist->remove();
}
return true;
}
endif;
/**
* Login Ajax
*/
add_action('wp_ajax_nopriv_nasa_process_login', 'elessi_process_login');
add_action('wp_ajax_nasa_process_login', 'elessi_process_login');
if (!function_exists('elessi_process_login')) :
function elessi_process_login() {
$mess = array(
'error' => '1',
'mess' => esc_html__('Error.', 'elessi-theme'),
'_wpnonce' => '0'
);
if (empty($_REQUEST['data'])) {
die(json_encode($mess));
}
$input = array();
foreach ($_REQUEST['data'] as $values) {
if (isset($values['name']) && isset($values['value'])) {
$input[$values['name']] = $values['value'];
}
}
if (isset($input['woocommerce-login-nonce'])) {
$nonce_value = $input['woocommerce-login-nonce'];
} else {
$nonce_value = isset($input['_wpnonce']) ? $input['_wpnonce'] : '';
}
// Check _wpnonce
if (!wp_verify_nonce($nonce_value, 'woocommerce-login')) {
$mess['_wpnonce'] = 'error';
die(json_encode($mess));
}
if (!empty($_REQUEST['login'])) {
$creds = array();
$username = trim($input['nasa_username']);
$validation_Obj = new WP_Error();
$validation_error = apply_filters('woocommerce_process_login_errors', $validation_Obj, $input['nasa_username'], $input['nasa_username']);
// Login error
if ($validation_error->get_error_code()) {
$mess['mess'] = '<strong>' . esc_html__('Error', 'elessi-theme') . ':</strong> ' . $validation_error->get_error_message();
die(json_encode($mess));
}
// Require username
if (empty($username)) {
$mess['mess'] = '<strong>' . esc_html__('Error', 'elessi-theme') . ':</strong> ' . esc_html__('Username is required.', 'elessi-theme');
die(json_encode($mess));
}
// Require Password
if (empty($input['nasa_password'])) {
$mess['mess'] = '<strong>' . esc_html__('Error', 'elessi-theme') . ':</strong> ' . esc_html__('Password is required.', 'elessi-theme');
die(json_encode($mess));
}
if (is_email($username) && apply_filters('woocommerce_get_username_from_email', true)) {
$user = get_user_by('email', $username);
if (!isset($user->user_login)) {
// Email error
$mess['mess'] = '<strong>' . esc_html__('Error', 'elessi-theme') . ':</strong> ' . esc_html__('A user could not be found with this email address.', 'elessi-theme');
die(json_encode($mess));
}
$creds['user_login'] = $user->user_login;
} else {
$creds['user_login'] = $username;
}
$creds['user_password'] = $input['nasa_password'];
$creds['remember'] = isset($input['nasa_rememberme']);
$secure_cookie = is_ssl() ? true : false;
$user = wp_signon(apply_filters('woocommerce_login_credentials', $creds), $secure_cookie);
if (is_wp_error($user)) {
// Other Error
$message = $user->get_error_message();
$mess['mess'] = str_replace(
'<strong>' . esc_html($creds['user_login']) . '</strong>',
'<strong>' . esc_html($username) . '</strong>',
$message
);
die(json_encode($mess));
} else {
// Login success
$mess['error'] = '0';
if (! empty($input['nasa_redirect'])) {
$redirect = $input['nasa_redirect'];
} else{
$redirect_uri = wp_get_referer();
$redirect = $redirect_uri ? $redirect_uri : (NASA_WOO_ACTIVED ? wc_get_page_permalink('myaccount') : home_url('/'));
}
$svg = '<svg class="svg-login-succes" width="60px" height="60px" viewBox="0 0 24.00 24.00" fill="currentColor" stroke-width="0.552"><g stroke-width="0"></g><g stroke-linecap="round" stroke-linejoin="round"></g><g> <path d="M10.5 15.25C10.307 15.2353 10.1276 15.1455 9.99998 15L6.99998 12C6.93314 11.8601 6.91133 11.7029 6.93756 11.55C6.96379 11.3971 7.03676 11.2562 7.14643 11.1465C7.2561 11.0368 7.39707 10.9638 7.54993 10.9376C7.70279 10.9114 7.86003 10.9332 7.99998 11L10.47 13.47L19 5.00004C19.1399 4.9332 19.2972 4.91139 19.45 4.93762C19.6029 4.96385 19.7439 5.03682 19.8535 5.14649C19.9632 5.25616 20.0362 5.39713 20.0624 5.54999C20.0886 5.70286 20.0668 5.86009 20 6.00004L11 15C10.8724 15.1455 10.6929 15.2353 10.5 15.25Z" fill="currentColor" /> <path d="M12 21C10.3915 20.9974 8.813 20.5638 7.42891 19.7443C6.04481 18.9247 4.90566 17.7492 4.12999 16.34C3.54037 15.29 3.17596 14.1287 3.05999 12.93C2.87697 11.1721 3.2156 9.39921 4.03363 7.83249C4.85167 6.26578 6.1129 4.9746 7.65999 4.12003C8.71001 3.53041 9.87134 3.166 11.07 3.05003C12.2641 2.92157 13.4719 3.03725 14.62 3.39003C14.7224 3.4105 14.8195 3.45215 14.9049 3.51232C14.9903 3.57248 15.0622 3.64983 15.116 3.73941C15.1698 3.82898 15.2043 3.92881 15.2173 4.03249C15.2302 4.13616 15.2214 4.2414 15.1913 4.34146C15.1612 4.44152 15.1105 4.53419 15.0425 4.61352C14.9745 4.69286 14.8907 4.75712 14.7965 4.80217C14.7022 4.84723 14.5995 4.87209 14.4951 4.87516C14.3907 4.87824 14.2867 4.85946 14.19 4.82003C13.2186 4.52795 12.1987 4.43275 11.19 4.54003C10.193 4.64212 9.22694 4.94485 8.34999 5.43003C7.50512 5.89613 6.75813 6.52088 6.14999 7.27003C5.52385 8.03319 5.05628 8.91361 4.77467 9.85974C4.49307 10.8059 4.40308 11.7987 4.50999 12.78C4.61208 13.777 4.91482 14.7431 5.39999 15.62C5.86609 16.4649 6.49084 17.2119 7.23999 17.82C8.00315 18.4462 8.88357 18.9137 9.8297 19.1953C10.7758 19.4769 11.7686 19.5669 12.75 19.46C13.747 19.3579 14.713 19.0552 15.59 18.57C16.4349 18.1039 17.1818 17.4792 17.79 16.73C18.4161 15.9669 18.8837 15.0864 19.1653 14.1403C19.4469 13.1942 19.5369 12.2014 19.43 11.22C19.4201 11.1169 19.4307 11.0129 19.461 10.9139C19.4914 10.8149 19.5409 10.7228 19.6069 10.643C19.6728 10.5631 19.7538 10.497 19.8453 10.4485C19.9368 10.3999 20.0369 10.3699 20.14 10.36C20.2431 10.3502 20.3471 10.3607 20.4461 10.3911C20.5451 10.4214 20.6372 10.471 20.717 10.5369C20.7969 10.6028 20.863 10.6839 20.9115 10.7753C20.9601 10.8668 20.9901 10.9669 21 11.07C21.1821 12.829 20.842 14.6026 20.0221 16.1695C19.2022 17.7363 17.9389 19.0269 16.39 19.88C15.3288 20.4938 14.1495 20.8755 12.93 21C12.62 21 12.3 21 12 21Z" /></g></svg>';
$mess['svg_check'] = apply_filters('ns_svg_login_congrat', $svg);
$mess['redirect'] = $redirect;
$mess['mess'] = sprintf(
wp_kses(
__('<h4 class="nasa-success-congrat">Congratulations!</h4><h4 class="nasa-success">You are now successfully authenticated. You can now close this tab, or visit <a class="link-your-dashboard primary-color" href="%s">your dashboard</a>.</h4>', 'elessi-theme'),
array(
'h4' => array('class' => array()),
'a' => array('class' => array(), 'href' => array())
)
),
esc_url(wc_get_page_permalink('myaccount'))
);
}
}
die(json_encode($mess));
}
endif;
/**
* Register Ajax
*/
add_action('wp_ajax_nopriv_nasa_process_register', 'elessi_process_register');
add_action('wp_ajax_nasa_process_register', 'elessi_process_register');
if (!function_exists('elessi_process_register')) :
function elessi_process_register() {
if (empty($_REQUEST['data'])) {
die;
}
$mess = array(
'error' => '1',
'mess' => esc_html__('Error.', 'elessi-theme'),
'_wpnonce' => '0'
);
$input = array();
foreach ($_REQUEST['data'] as $values) {
if (isset($values['name']) && isset($values['value'])) {
$input[$values['name']] = $values['value'];
}
}
if (isset($input['woocommerce-register-nonce'])) {
$nonce_value = $input['woocommerce-register-nonce'];
} else {
$nonce_value = isset($input['_wpnonce']) ? $input['_wpnonce'] : '';
}
if (! empty($_REQUEST['register'])) {
$_POST = $input;
// Check _wpnonce
if (!wp_verify_nonce($nonce_value, 'woocommerce-register')) {
$mess['_wpnonce'] = 'error';
die(json_encode($mess));
}
$username = 'no' === get_option('woocommerce_registration_generate_username') ? $_POST['nasa_username'] : '';
$password = 'no' === get_option('woocommerce_registration_generate_password') ? $_POST['nasa_password'] : '';
$email = $_POST['nasa_email'];
$validation_Obj = new WP_Error();
$validation_error = apply_filters('woocommerce_process_registration_errors', $validation_Obj, $username, $password, $email);
if ($validation_error->get_error_code()) {
$mess['mess'] = $validation_error->get_error_message();
die(json_encode($mess));
}
$new_customer = wc_create_new_customer(sanitize_email($email), wc_clean($username), $password);
if (is_wp_error($new_customer)) {
$mess['mess'] = $new_customer->get_error_message();
die(json_encode($mess));
}
if (apply_filters('woocommerce_registration_auth_new_customer', true, $new_customer)) {
wc_set_customer_auth_cookie($new_customer);
}
// Register success.
$svg = '<svg class="svg-login-succes" width="60px" height="60px" viewBox="0 0 24.00 24.00" fill="currentColor" stroke-width="0.552"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M10.5 15.25C10.307 15.2353 10.1276 15.1455 9.99998 15L6.99998 12C6.93314 11.8601 6.91133 11.7029 6.93756 11.55C6.96379 11.3971 7.03676 11.2562 7.14643 11.1465C7.2561 11.0368 7.39707 10.9638 7.54993 10.9376C7.70279 10.9114 7.86003 10.9332 7.99998 11L10.47 13.47L19 5.00004C19.1399 4.9332 19.2972 4.91139 19.45 4.93762C19.6029 4.96385 19.7439 5.03682 19.8535 5.14649C19.9632 5.25616 20.0362 5.39713 20.0624 5.54999C20.0886 5.70286 20.0668 5.86009 20 6.00004L11 15C10.8724 15.1455 10.6929 15.2353 10.5 15.25Z" fill="currentColor" /> <path d="M12 21C10.3915 20.9974 8.813 20.5638 7.42891 19.7443C6.04481 18.9247 4.90566 17.7492 4.12999 16.34C3.54037 15.29 3.17596 14.1287 3.05999 12.93C2.87697 11.1721 3.2156 9.39921 4.03363 7.83249C4.85167 6.26578 6.1129 4.9746 7.65999 4.12003C8.71001 3.53041 9.87134 3.166 11.07 3.05003C12.2641 2.92157 13.4719 3.03725 14.62 3.39003C14.7224 3.4105 14.8195 3.45215 14.9049 3.51232C14.9903 3.57248 15.0622 3.64983 15.116 3.73941C15.1698 3.82898 15.2043 3.92881 15.2173 4.03249C15.2302 4.13616 15.2214 4.2414 15.1913 4.34146C15.1612 4.44152 15.1105 4.53419 15.0425 4.61352C14.9745 4.69286 14.8907 4.75712 14.7965 4.80217C14.7022 4.84723 14.5995 4.87209 14.4951 4.87516C14.3907 4.87824 14.2867 4.85946 14.19 4.82003C13.2186 4.52795 12.1987 4.43275 11.19 4.54003C10.193 4.64212 9.22694 4.94485 8.34999 5.43003C7.50512 5.89613 6.75813 6.52088 6.14999 7.27003C5.52385 8.03319 5.05628 8.91361 4.77467 9.85974C4.49307 10.8059 4.40308 11.7987 4.50999 12.78C4.61208 13.777 4.91482 14.7431 5.39999 15.62C5.86609 16.4649 6.49084 17.2119 7.23999 17.82C8.00315 18.4462 8.88357 18.9137 9.8297 19.1953C10.7758 19.4769 11.7686 19.5669 12.75 19.46C13.747 19.3579 14.713 19.0552 15.59 18.57C16.4349 18.1039 17.1818 17.4792 17.79 16.73C18.4161 15.9669 18.8837 15.0864 19.1653 14.1403C19.4469 13.1942 19.5369 12.2014 19.43 11.22C19.4201 11.1169 19.4307 11.0129 19.461 10.9139C19.4914 10.8149 19.5409 10.7228 19.6069 10.643C19.6728 10.5631 19.7538 10.497 19.8453 10.4485C19.9368 10.3999 20.0369 10.3699 20.14 10.36C20.2431 10.3502 20.3471 10.3607 20.4461 10.3911C20.5451 10.4214 20.6372 10.471 20.717 10.5369C20.7969 10.6028 20.863 10.6839 20.9115 10.7753C20.9601 10.8668 20.9901 10.9669 21 11.07C21.1821 12.829 20.842 14.6026 20.0221 16.1695C19.2022 17.7363 17.9389 19.0269 16.39 19.88C15.3288 20.4938 14.1495 20.8755 12.93 21C12.62 21 12.3 21 12 21Z" fill="currentColor" /></g></svg>';
$mess['svg_check'] = apply_filters('ns_svg__login_congrat',$svg);
$mess['error'] = '0';
$redirect_uri = wp_get_referer();
$mess['redirect'] = apply_filters('woocommerce_registration_redirect', $redirect_uri ? $redirect_uri : (NASA_WOO_ACTIVED ? wc_get_page_permalink('myaccount') : home_url('/')));
$mess['mess'] = sprintf(
wp_kses(
__('<h4 class="nasa-success-congrat">Congratulations!</h4><h4 class="nasa-success">Now you have successfully registered. You can now close this tab, or visit <a class="link-your-dashboard primary-color" href="%s">your dashboard</a>.</h4>', 'elessi-theme'),
array(
'h4' => array('class' => array()),
'a' => array('class' => array(), 'href'=>array())
)
),
esc_url(wc_get_page_permalink('myaccount'))
);
}
die(json_encode($mess));
}
endif;
/**
* Live search admin ajax
*/
add_action('wp_ajax_nopriv_live_search_products', 'elessi_live_search_products');
add_action('wp_ajax_live_search_products', 'elessi_live_search_products');
if (!function_exists('elessi_live_search_products')) :
function elessi_live_search_products() {
global $nasa_opt, $woocommerce;
$results = array();
if (!$woocommerce || !isset($_REQUEST['s']) || trim($_REQUEST['s']) == '') {
die(json_encode($results));
}
$data_store = WC_Data_Store::load('product');
$post_id_in = $data_store->search_products(wc_clean($_REQUEST['s']), '', true, true);
if (empty($post_id_in)) {
die(json_encode($results));
}
$query_args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => (isset($nasa_opt['limit_results_search']) && (int) $nasa_opt['limit_results_search'] > 0) ? (int) $nasa_opt['limit_results_search'] : 5,
'no_found_rows' => true
);
$query_args['meta_query'] = array();
$query_args['meta_query'][] = $woocommerce->query->stock_status_meta_query();
$query_args['meta_query'][] = $woocommerce->query->visibility_meta_query();
$query_args['post__in'] = array_merge($post_id_in, array(0));
$query_args['tax_query'] = array('relation' => 'AND');
$product_visibility_terms = wc_get_product_visibility_term_ids();
$arr_not_in = array($product_visibility_terms['exclude-from-search']);
// Hide out of stock products.
if ('yes' === get_option('woocommerce_hide_out_of_stock_items')) {
$arr_not_in[] = $product_visibility_terms['outofstock'];
}
if (!empty($arr_not_in)) {
$query_args['tax_query'][] = array(
'taxonomy' => 'product_visibility',
'field' => 'term_taxonomy_id',
'terms' => $arr_not_in,
'operator' => 'NOT IN',
);
}
$search_query = new WP_Query(apply_filters('nasa_query_live_search_products', $query_args));
if ($the_posts = $search_query->get_posts()) {
foreach ($the_posts as $the_post) {
if ($product = wc_get_product($the_post->ID)) {
$results[] = array(
'title' => $product->get_name(),
'url' => $product->get_permalink(),
'image' => $product->get_image('thumbnail'),
'price' => $product->get_price_html()
);
}
}
}
wp_reset_postdata();
die(json_encode($results));
}
endif;
/**
* Support Multi currency - AJAX
*/
if (class_exists('WCML_Multi_Currency')) :
add_filter('wcml_multi_currency_ajax_actions', 'elessi_multi_currency_ajax', 10, 1);
if (!function_exists('elessi_multi_currency_ajax')) :
function elessi_multi_currency_ajax($ajax_actions) {
return elessi_ajax_actions($ajax_actions);
}
endif;
endif;
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+556
View File
@@ -0,0 +1,556 @@
<?php
defined('ABSPATH') or die(); // Exit if accessed directly
/**
* VC SETUP
*/
add_action('init', 'elessi_vc_setup');
if (!function_exists('elessi_vc_setup')) :
function elessi_vc_setup() {
if (!NASA_WPB_ACTIVE){
return;
}
global $nasa_opt;
/**
* Row (add fullwidth)
*/
vc_add_param('vc_row', array(
"type" => 'checkbox',
"heading" => esc_html__("Fullwidth ?", 'elessi-theme'),
"param_name" => "fullwidth",
"value" => array(
esc_html__('Yes, Please!', 'elessi-theme') => '1'
)
));
/**
* Add param from row element
*/
vc_add_param('vc_row', array(
"type" => "dropdown",
"heading" => esc_html__("Width full side", 'elessi-theme'),
"param_name" => "width_side",
'value' => array(
esc_html__('None', 'elessi-theme') => '',
esc_html__('Full width to left', 'elessi-theme') => 'left',
esc_html__('Full width to right', 'elessi-theme') => 'right'
),
'std' => '',
"description" => esc_html__('Only use for Visual Composer Template.', 'elessi-theme'),
));
/**
* Add params from tab element
*/
vc_add_param('vc_tta_tabs', array(
"type" => "dropdown",
"heading" => esc_html__("Font Size Title", 'elessi-theme'),
"param_name" => "title_font_size",
"value" => array(
esc_html__('Not Set', 'elessi-theme') => '',
esc_html__('X-Large', 'elessi-theme') => 'xl',
esc_html__('Large', 'elessi-theme') => 'l',
esc_html__('Medium', 'elessi-theme') => 'm',
esc_html__('Small', 'elessi-theme') => 's',
esc_html__('Tiny', 'elessi-theme') => 't'
),
"std" => ''
));
vc_add_param('vc_tta_tabs', array(
"type" => "dropdown",
"heading" => esc_html__("Style", 'elessi-theme'),
"param_name" => "tabs_display_type",
"value" => array(
esc_html__('Classic 2D - No border', 'elessi-theme') => '2d-no-border',
esc_html__('Classic 2D - Radius', 'elessi-theme') => '2d-radius',
esc_html__('Classic 2D - Radius - Dash', 'elessi-theme') => '2d-radius-dashed',
esc_html__('Classic 2D - Has BG color', 'elessi-theme') => '2d-has-bg',
esc_html__('Classic 2D', 'elessi-theme') => '2d',
esc_html__('Classic 3D', 'elessi-theme') => '3d',
esc_html__('Slide', 'elessi-theme') => 'slide',
esc_html__('Vertical', 'elessi-theme') => 'ver'
),
"std" => '2d-no-border'
));
vc_add_param('vc_tta_tabs', array(
"type" => "colorpicker",
"heading" => esc_html__("Tabs Background color", 'elessi-theme'),
"param_name" => "tabs_bg_color",
"std" => '#efefef',
"dependency" => array(
"element" => "tabs_display_type",
"value" => array(
"2d-has-bg"
)
)
));
vc_add_param('vc_tta_tabs', array(
"type" => "colorpicker",
"heading" => esc_html__("Tabs text color", 'elessi-theme'),
"param_name" => "tabs_text_color",
"std" => '',
"dependency" => array(
"element" => "tabs_display_type",
"value" => array(
"2d-has-bg"
)
)
));
vc_add_param('vc_tta_accordion', array(
"type" => "dropdown",
"heading" => esc_html__("Layout", 'elessi-theme'),
"param_name" => "accordion_layout",
'value' => array(
esc_html__('Border Wrapper', 'elessi-theme') => 'has-border',
esc_html__('Without Border Wrapper', 'elessi-theme') => 'no-border'
),
'std' => 'has-border',
"description" => esc_html__('Only use for Accordion.', 'elessi-theme'),
));
vc_add_param('vc_tta_accordion', array(
"type" => "dropdown",
"heading" => esc_html__("Toggle Icon", 'elessi-theme'),
"param_name" => "accordion_icon",
'value' => array(
esc_html__('Plus', 'elessi-theme') => 'plus',
esc_html__('Arrow', 'elessi-theme') => 'arrow'
),
'std' => 'plus',
"description" => esc_html__('Only use for Accordion.', 'elessi-theme'),
));
vc_add_param('vc_tta_accordion', array(
"type" => 'checkbox',
"heading" => esc_html__("Hide First Section ?", 'elessi-theme'),
"param_name" => "accordion_hide_first",
"value" => array(
esc_html__('Yes, Please!', 'elessi-theme') => '1'
)
));
vc_add_param('vc_tta_accordion', array(
"type" => 'checkbox',
"heading" => esc_html__("Show Multi", 'elessi-theme'),
"param_name" => "accordion_show_multi",
"value" => array(
esc_html__('Yes, Please!', 'elessi-theme') => '1'
)
));
/**
* Add params from section tab element
*/
vc_add_param('vc_tta_section', array(
"type" => "textfield",
"heading" => esc_html__("Add Icon NasaTheme (Using for Section of Tabs)", 'elessi-theme'),
"param_name" => "section_nasa_icon",
"std" => '',
'readonly' => 1,
'description' => '<a class="nasa-chosen-icon left" data-fill="section_nasa_icon" href="javascript:void(0);">Click Here to Add Icon NasaTheme</a><a class="nasa-remove-icon right" data-id="section_nasa_icon" href="javascript:void(0);">Remove Icon NasaTheme</a><p class="nasa-clearfix"></p>'
));
/**
* Add params image for Tab
*/
vc_add_param('vc_tta_section', array(
"type" => "attach_image",
"heading" => esc_html__("Add Icon Image (Using for Section of Tabs)", 'elessi-theme'),
"param_name" => "section_nasa_img",
"std" => '',
'description' => '',
'admin_label' => true,
));
vc_add_param('vc_tta_section', array(
"type" => "textarea_raw_html",
"heading" => esc_html__("Before Tabs Title (Using for Section of Tabs)", 'elessi-theme'),
"param_name" => "before_tab_title",
"std" => ''
));
vc_add_param('vc_tta_section', array(
"type" => "textarea_raw_html",
"heading" => esc_html__("After Tabs Title (Using for Section of Tabs)", 'elessi-theme'),
"param_name" => "after_tab_title",
"std" => ''
));
/**
* For Mobile Layout
*/
$option_mobile = !isset($nasa_opt['enable_nasa_mobile']) || $nasa_opt['enable_nasa_mobile'] ? true : false;
if ($option_mobile) {
/**
* Hide on mobile for Row
*/
vc_add_param('vc_row', array(
"type" => 'checkbox',
"heading" => esc_html__("Ignore on Mobile", 'elessi-theme'),
"param_name" => "hide_in_mobile",
"value" => array(
esc_html__('Yes, Please!', 'elessi-theme') => '1'
)
));
/**
* Hide on mobile for Mobile
*/
vc_add_param('vc_column', array(
"type" => 'checkbox',
"heading" => esc_html__("Ignore on Mobile", 'elessi-theme'),
"param_name" => "hide_in_mobile",
"value" => array(
esc_html__('Yes, Please!', 'elessi-theme') => '1'
)
));
}
/**
* Custom shortcode
*/
$param_nasa_sc_icons = array(
"name" => esc_html__("Header Icons", 'elessi-theme'),
"base" => "nasa_sc_icons",
'icon' => 'icon-wpb-nasatheme',
'description' => esc_html__("Header icons Cart | Wishlist | Compare", 'elessi-theme'),
"category" => esc_html__('Header Builder', 'elessi-theme'),
"params" => array(
array(
"type" => "dropdown",
"heading" => esc_html__("Show Mini Account", 'elessi-theme'),
"param_name" => "show_mini_acc",
"value" => array(
esc_html__('Yes', 'elessi-theme') => 'yes',
esc_html__('No', 'elessi-theme') => 'no'
),
"std" => 'yes',
"admin_label" => true
),
array(
"type" => "dropdown",
"heading" => esc_html__("Show Mini Cart", 'elessi-theme'),
"param_name" => "show_mini_cart",
"value" => array(
esc_html__('Yes', 'elessi-theme') => 'yes',
esc_html__('No', 'elessi-theme') => 'no'
),
"std" => 'yes',
"admin_label" => true
),
array(
"type" => "dropdown",
"heading" => esc_html__("Show Mini Compare", 'elessi-theme'),
"param_name" => "show_mini_compare",
"value" => array(
esc_html__('Yes', 'elessi-theme') => 'yes',
esc_html__('No', 'elessi-theme') => 'no'
),
"std" => 'yes',
"admin_label" => true
),
array(
"type" => "dropdown",
"heading" => esc_html__("Show Mini Wishlist", 'elessi-theme'),
"param_name" => "show_mini_wishlist",
"value" => array(
esc_html__('Yes', 'elessi-theme') => 'yes',
esc_html__('No', 'elessi-theme') => 'no'
),
"std" => 'yes',
"admin_label" => true
),
array(
"type" => "textfield",
"heading" => esc_html__("Extra class name", 'elessi-theme'),
"param_name" => "el_class",
"description" => esc_html__("If you wish to style particular content element differently, then use this field to add a class name and then refer to it in your css file.", 'elessi-theme')
)
)
);
vc_map($param_nasa_sc_icons);
/**
* Search form in header
*/
$param_nasa_search = array(
"name" => esc_html__("Header Search", 'elessi-theme'),
"base" => "nasa_sc_search_form",
'icon' => 'icon-wpb-nasatheme',
'description' => esc_html__("Header search form", 'elessi-theme'),
"category" => esc_html__('Header Builder', 'elessi-theme'),
"params" => array(
array(
"type" => "textfield",
"heading" => esc_html__("Extra class name", 'elessi-theme'),
"param_name" => "el_class",
"description" => esc_html__("If you wish to style particular content element differently, then use this field to add a class name and then refer to it in your css file.", 'elessi-theme')
)
)
);
vc_map($param_nasa_search);
// if (function_exists('nasa_header_icons_sc')) {
// add_shortcode('nasa_sc_icons', 'nasa_header_icons_sc');
// }
// if (function_exists('nasa_header_search_sc')) {
// add_shortcode('nasa_sc_search_form', 'nasa_header_search_sc');
// }
}
endif;
/* add_filter('vc_map_get_attributes', 'elessi_ct_attrs_tabs', 10, 2);
if (!function_exists('elessi_ct_attrs_tabs')) :
function elessi_ct_attrs_tabs($atts, $tag) {
if ($tag == 'vc_tta_section') {
$atts['before_tab_title'] = $atts['before_tab_title'] ? html_entity_decode($atts['before_tab_title']) : '';
$atts['after_tab_title'] = $atts['after_tab_title'] ? html_entity_decode($atts['after_tab_title']) : '';
}
return $atts;
}
endif; */
/**
* Support Upload SVG Media
*/
add_filter('upload_mimes', 'elessi_enable_svg_upload', 10, 1);
if (!function_exists('elessi_enable_svg_upload')) :
function elessi_enable_svg_upload($mimes) {
global $nasa_opt;
if (!isset($nasa_opt['sp_upload_svg']) || $nasa_opt['sp_upload_svg']) {
$mimes['svg'] = 'image/svg+xml';
$mimes['svgz'] = 'image/svg+xml';
}
return $mimes;
}
endif;
/**
* *.ico check
*/
add_filter('wp_check_filetype_and_ext', 'elessi_check_ico_ext', 10, 4);
if (!function_exists('elessi_check_ico_ext')) :
function elessi_check_ico_ext($types, $file, $filename, $mimes) {
global $nasa_opt;
if (isset($nasa_opt['sp_upload_ico']) && $nasa_opt['sp_upload_ico']) {
if (false !== strpos($filename, '.ico')) {
$types['ext'] = 'ico';
$types['type'] = 'image/ico';
}
}
return $types;
}
endif;
/**
* Support Upload ICO Media
*/
add_filter('upload_mimes', 'elessi_enable_ico_upload', 10, 1);
if (!function_exists('elessi_enable_ico_upload')) :
function elessi_enable_ico_upload($mimes) {
global $nasa_opt;
if (isset($nasa_opt['sp_upload_ico']) && $nasa_opt['sp_upload_ico']) {
$mimes['ico'] = 'image/ico';
}
return $mimes;
}
endif;
/**
* HTML Loader
*/
if (!function_exists('elessi_loader_html')) :
function elessi_loader_html($id_attr = null, $relative = true) {
$id = $id_attr != null ? ' id="' . esc_attr($id_attr) . '"' : '';
$class = $relative ? ' class="nasa-relative nasa-fullsize"' : '';
return
'<div' . $id . $class . '>' .
'<div class="nasa-loader"></div>' .
'</div>';
}
endif;
/**
* Start captcha
*/
if (!function_exists('elessi_start_session')) :
function elessi_start_session() {
if (!session_id()) {
session_start();
}
}
endif;
/**
* Captcha for Register form
*/
add_action('init', 'elessi_register_field_captcha_img');
if (!function_exists('elessi_register_field_captcha_img')) :
function elessi_register_field_captcha_img() {
global $nasa_opt;
if (!isset($nasa_opt['register_captcha']) || !$nasa_opt['register_captcha']) {
return;
}
/**
* No support - server no support create image
*/
if (!function_exists('imagecreatetruecolor')) {
return;
}
if (isset($_REQUEST['nasa-captcha-register']) && $_REQUEST['nasa-captcha-register'] === '1') {
require_once ELESSI_THEME_PATH . '/cores/nasa-captcha.php';
$captcha = new Nasa_Captcha();
if (!$captcha) {
return;
}
$code = $captcha->get_and_show_image();
elessi_start_session();
// Save code session
$_SESSION['nasa_captcha_code_' . $_REQUEST['nasa-captcha-register']] = $code;
// Save code cookie
// setcookie('nasa_captcha_code_' . $_REQUEST['nasa-captcha-register'], $code, time() + 300, "/");
die();
}
return;
}
endif;
/**
* Add field captcha for Register form
*/
add_action('woocommerce_register_form', 'elessi_register_form_field_captcha');
if (!function_exists('elessi_register_form_field_captcha')) :
function elessi_register_form_field_captcha() {
global $nasa_opt;
if (!isset($nasa_opt['register_captcha']) || !$nasa_opt['register_captcha']) {
return;
}
/**
* No support - server no support create image
*/
if (!function_exists('imagecreatetruecolor')) {
return;
}
echo '<p class="nasa-form-row-captcha hidden-tag"></p>';
}
endif;
/**
* Check error Captcha
*/
add_filter('woocommerce_registration_errors', 'elessi_check_captcha_registration_errors', 10, 3);
if (!function_exists('elessi_check_captcha_registration_errors')) :
function elessi_check_captcha_registration_errors($errors, $username, $email) {
global $nasa_opt;
/**
* Disable check Captcha
*/
if (!isset($nasa_opt['register_captcha']) || !$nasa_opt['register_captcha']) {
return $errors;
}
/**
* No support - server no support create image
*/
if (!function_exists('imagecreatetruecolor')) {
return $errors;
}
/**
* Ignore when Create Account in Checkout page
*/
if (isset($_REQUEST['wc-ajax']) && $_REQUEST['wc-ajax'] == 'checkout') {
return $errors;
}
/**
* Init check
*/
$input = array();
/**
* For Ajax form
*/
if (isset($_REQUEST['data']) && $_REQUEST['data']) {
foreach ($_REQUEST['data'] as $values) {
if (isset($values['name']) && isset($values['value'])) {
$input[$values['name']] = $values['value'];
}
}
}
/**
* For Default form
*/
else {
if (isset($_REQUEST['nasa-captcha-key'])) {
$input['nasa-captcha-key'] = $_REQUEST['nasa-captcha-key'];
}
if (isset($_REQUEST['nasa-input-captcha'])) {
$input['nasa-input-captcha'] = $_REQUEST['nasa-input-captcha'];
}
}
/**
* Check error Captcha
*/
elessi_start_session();
if (
!isset($input['nasa-captcha-key']) ||
!isset($input['nasa-input-captcha']) ||
!isset($_SESSION['nasa_captcha_code_' . $input['nasa-captcha-key']]) ||
$_SESSION['nasa_captcha_code_' . $input['nasa-captcha-key']] != strtolower($input['nasa-input-captcha'])) {
$errors->add('nasa-captcha-register', esc_html__('Captcha Error!', 'elessi-theme'));
}
return $errors;
}
endif;
/**
* Fix style WooCommerce Stripe
*/
add_filter('wc_stripe_upe_params', function ($stripe_params) {
$stripe_params['appearance'] = (object) array(
'theme' => 'flat'
);
return $stripe_params;
});
+125
View File
@@ -0,0 +1,125 @@
<?php
defined('ABSPATH') or die(); // Exit if accessed directly
/**
* Extended WooCommerce Checkout
*/
if (class_exists('WC_Checkout')) :
class Elessi_WC_Checkout_Ext extends WC_Checkout {
/**
* The single instance of the class.
*
* @var Elessi_WC_Checkout_Ext|null
*/
protected static $instance_child = null;
/**
* Gets the main WC_Checkout Instance.
*
* @static
* @return WC_Checkout Main instance
*/
public static function instance_child() {
if (is_null(self::$instance_child)) {
self::$instance_child = new self();
// Hook in actions once.
add_action('woocommerce_checkout_billing', array(self::$instance_child, 'checkout_form_billing'));
add_action('woocommerce_checkout_shipping', array(self::$instance_child, 'checkout_form_shipping'));
// woocommerce_checkout_init action is ran once when the class is first constructed.
do_action('woocommerce_checkout_init', self::$instance_child);
}
return self::$instance_child;
}
/**
* Validate form checkout
*/
public function validate_form_checkout() {
try {
$errors = new WP_Error();
$posted_data = $this->get_posted_data();
// Update session for customer and totals.
$this->update_session($posted_data);
// Validate posted data and cart items before proceeding.
$this->validate_checkout_no_payment($posted_data, $errors);
if (!empty($errors->errors)) {
foreach ($errors->errors as $code => $messages) {
$data = $errors->get_error_data($code);
foreach ($messages as $message) {
wc_add_notice($message, 'error', $data);
}
}
}
} catch (Exception $e) {
wc_add_notice($e->getMessage(), 'error');
}
if (wc_notice_count('error') > 0) {
$this->send_ajax_failure_response();
} else {
$response = array(
'result' => 'success'
);
wp_send_json($response);
}
}
/**
* Validates that the checkout has enough info to proceed.
*
* @param array $data An array of posted data.
* @param WP_Error $errors Validation errors.
*/
protected function validate_checkout_no_payment(&$data, &$errors) {
$this->validate_posted_data($data, $errors);
$this->check_cart_items();
if (WC()->cart->needs_shipping()) {
$shipping_country = isset($data['shipping_country']) ? $data['shipping_country'] : WC()->customer->get_shipping_country();
if (empty($shipping_country)) {
$errors->add('shipping', __('Please enter an address to continue.', 'elessi-theme'));
} elseif (!in_array($shipping_country, array_keys(WC()->countries->get_shipping_countries()), true)) {
if (WC()->countries->country_exists($shipping_country)) {
/* translators: %s: shipping location (prefix e.g. 'to' + ISO 3166-1 alpha-2 country code) */
$errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'elessi-theme'), WC()->countries->shipping_to_prefix() . ' ' . $shipping_country));
}
} else {
$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
foreach (WC()->shipping()->get_packages() as $i => $package) {
if (!isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) {
$errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'elessi-theme'));
}
}
}
}
/**
* Ignore validate checkbox with Germanized for WooCommerce plugin
*/
if (class_exists('WC_GZD_Legal_Checkbox_Manager')) {
$gzd = WC_GZD_Legal_Checkbox_Manager::instance();
remove_action('woocommerce_after_checkout_validation', array($gzd, 'validate_checkout'), 1, 2);
}
/**
* Hook after checkout validation
*/
do_action('woocommerce_after_checkout_validation', $data, $errors);
}
}
endif;
+631
View File
@@ -0,0 +1,631 @@
<?php
defined('ABSPATH') or die(); // Exit if accessed directly
/**
* Get Role Filter Price
*/
if (!function_exists('elessi_get_filtered_price')) :
function elessi_get_filtered_price() {
global $wpdb;
$args = WC()->query->get_main_query()->query_vars;
$tax_query = isset($args['tax_query']) ? $args['tax_query'] : array();
$meta_query = isset($args['meta_query']) ? $args['meta_query'] : array();
if (!is_post_type_archive('product') && !empty($args['taxonomy']) && !empty($args['term'])) {
$tax_query[] = WC()->query->get_main_tax_query();
}
foreach ($meta_query + $tax_query as $key => $query) {
if (!empty($query['price_filter']) || ! empty($query['rating_filter'])) {
unset($meta_query[$key]);
}
}
$meta_query = new WP_Meta_Query($meta_query);
$tax_query = new WP_Tax_Query($tax_query);
$search = WC_Query::get_main_search_query_sql();
$meta_query_sql = $meta_query->get_sql('post', $wpdb->posts, 'ID');
$tax_query_sql = $tax_query->get_sql($wpdb->posts, 'ID');
$search_query_sql = $search ? ' AND ' . $search : '';
$sql = "
SELECT min(min_price) as min_price, MAX(max_price) as max_price
FROM {$wpdb->wc_product_meta_lookup}
WHERE product_id IN (
SELECT ID FROM {$wpdb->posts}
" . $tax_query_sql['join'] . $meta_query_sql['join'] . "
WHERE {$wpdb->posts}.post_type IN ('" . implode("','", array_map('esc_sql', apply_filters('woocommerce_price_filter_post_type', array('product')))) . "')
AND {$wpdb->posts}.post_status = 'publish'
" . $tax_query_sql['where'] . $meta_query_sql['where'] . $search_query_sql . '
)';
$sql = apply_filters('woocommerce_price_filter_sql', $sql, $meta_query_sql, $tax_query_sql);
return $wpdb->get_row($sql); // WPCS: unprepared SQL ok.
}
endif;
/**
* Variation content widget
*/
if (!function_exists('elessi_get_content_widget_variation')) :
function elessi_get_content_widget_variation($args, $instance) {
$args = array('widget_id' => $args['widget_id']);
$hide_widget = false;
$hide_empty = isset($instance['hide_empty']) && $instance['hide_empty'] ? true : false;
$var_exist = $hide_empty ? false : true;
$columns_classic = isset($instance['cols']) && in_array($instance['cols'], array('1', '2')) ? $instance['cols'] : '2';
$columns_classic_class = ' ns-cols-' . $columns_classic;
$taxonomy = isset($instance['attribute']) ? wc_attribute_taxonomy_name($instance['attribute']) : '';
if (!taxonomy_exists($taxonomy)) {
$hide_widget = true;
return array('hide_widget' => $hide_widget, 'content' => '');
}
$content = '<div id="' . esc_attr($args['widget_id']) . '-ajax-wrap" class="nasa-filter-variations-widget-wrap">';
$query_type = isset($instance['query_type']) ? $instance['query_type'] : 'or';
$terms_args = array('taxonomy' => $taxonomy, 'hide_empty' => $hide_empty);
$orderby = wc_attribute_orderby($taxonomy);
switch ($orderby) {
case 'name' :
$terms_args['orderby'] = 'name';
$terms_args['menu_order'] = false;
break;
case 'id' :
$terms_args['orderby'] = 'id';
$terms_args['order'] = 'ASC';
$terms_args['menu_order'] = false;
break;
case 'menu_order' :
default:
$terms_args['menu_order'] = 'ASC';
break;
}
$terms = get_terms(apply_filters('woocommerce_product_attribute_terms', $terms_args));
$hasResult = false;
$count_terms = $terms ? count($terms) : 0;
if (0 < $count_terms) {
$term_counts = elessi_get_filtered_term_product_counts(wp_list_pluck($terms, 'term_id'), $taxonomy, $query_type);
$attr_name = 0 === strpos($taxonomy, 'pa_') ? substr($taxonomy, 3) : $taxonomy;
$filter_name = 'filter_' . $attr_name;
$current_filter = array();
if (isset($_GET[$filter_name]) && $_GET[$filter_name] != '') {
$current_filter = is_array($_GET[$filter_name]) ?
$_GET[$filter_name] : explode(',', wc_clean($_GET[$filter_name]));
}
$current_filter = !empty($current_filter) ? array_map('sanitize_title', $current_filter) : $current_filter;
$vari_type = 'default';
$taxonomyObj = null;
$color_size = false;
$color_switch = 'color';
$label_switch = 'label';
$image_switch = 'image';
if ($nasa_attr_ux_exist = class_exists('Nasa_Abstract_WC_Attr_UX')) {
$taxonomyObj = Nasa_Abstract_WC_Attr_UX::get_tax_attribute($taxonomy);
$color_switch = Nasa_Abstract_WC_Attr_UX::_NASA_COLOR;
$label_switch = Nasa_Abstract_WC_Attr_UX::_NASA_LABEL;
$image_switch = Nasa_Abstract_WC_Attr_UX::_NASA_IMAGE;
}
$class_ul = ' small-block-grid-1 medium-block-grid-4 large-block-grid-5';
$brand_items = false;
if ($taxonomyObj && isset($taxonomyObj->attribute_type)) {
$color_size = true;
switch ($taxonomyObj->attribute_type) {
case $color_switch:
$vari_type = 'color';
$class_ul = ' small-block-grid-2 medium-block-grid-4 large-block-grid-7';
break;
case $label_switch:
$vari_type = 'size';
$class_ul = ' small-block-grid-2 medium-block-grid-4 large-block-grid-7';
break;
case $image_switch:
$vari_type = 'image';
global $nasa_opt;
$brands = array();
$nasa_brands = isset($nasa_opt['attr_brands']) && !empty($nasa_opt['attr_brands']) ?
$nasa_opt['attr_brands'] : array();
if (!empty($nasa_brands)) {
foreach ($nasa_brands as $key => $val) {
if ($val === '1') {
$brands[] = $key;
}
}
}
if (!empty($brands) && in_array($attr_name, $brands)) {
$class_ul = ' nasa-variation-filters-brands small-block-grid-2 medium-block-grid-4 large-block-grid-6';
$brand_items = true;
}
break;
default :
$color_size = false;
break;
}
}
$class_ul .= $columns_classic_class;
$show_items = isset($instance['show_items']) ? (int) $instance['show_items'] : 0;
// Current term
$queryObj = get_queried_object();
$current_term_slug = absint((is_tax() && isset($queryObj->slug)) ? $queryObj->slug : 0);
$_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes();
$content_li = '';
foreach ($terms as $k => $term) {
$count = isset($term_counts[$term->term_id]) ? $term_counts[$term->term_id] : 0;
$term_meta = $color_size ? get_term_meta($term->term_id, $taxonomyObj->attribute_type, true) : null;
$vari_txt = ($vari_type == 'size' && trim($term_meta) != '') ? $term_meta : $term->name;
$content_text = '<span class="nasa-text-variation nasa-text-variation-' . $vari_type . '">';
$content_text .= $vari_txt;
$content_text .= '</span>';
/**
* Link
*/
$current_filter_term = $current_filter;
$current_values = isset($_chosen_attributes[$taxonomy]['terms']) ? $_chosen_attributes[$taxonomy]['terms'] : array();
$option_is_set = in_array($term->slug, $current_values);
if (!in_array($term->slug, $current_filter_term)) {
$current_filter_term[] = $term->slug;
}
$link = elessi_get_page_base_url($taxonomy);
// Add current filters to URL.
foreach ($current_filter_term as $key => $value) {
// Exclude query arg for current term archive term
if ($value === $current_term_slug) {
unset($current_filter_term[$key]);
}
// Exclude self so filter can be unset on click.
if ($option_is_set && $value === $term->slug) {
unset($current_filter_term[$key]);
}
}
if (!empty($current_filter_term)) {
$link = add_query_arg($filter_name, implode(',', $current_filter_term), $link);
// Add Query type Arg to URL
if ('or' === $query_type && !(1 === sizeof($current_filter_term) && $option_is_set)) {
$attr_name = 0 === strpos($taxonomy, 'pa_') ? substr($taxonomy, 3) : $taxonomy;
$link = add_query_arg('query_type_' . sanitize_title($attr_name), 'or', $link);
}
// $link = str_replace('%2C', ',', $link);
}
if ($count > 0 || $option_is_set) {
$link = apply_filters('woocommerce_layered_nav_link', $link, $term, $taxonomy);
}
/**
* Current Filter = this widget
*/
$aclass = 'nasa-filter-by-variations nasa-filter-by-attrs';
$class = '';
if (isset($current_filter) && is_array($current_filter) && in_array($term->slug, $current_filter)) {
$class .= ' chosen nasa-chosen';
$aclass .= ' nasa-filter-var-chosen';
}
$countClss = 'count';
if ($vari_type != '') {
$class .= ' nasa-li-filter-' . $vari_type;
$aclass .= ' nasa-filter-' . $vari_type;
$countClss .= ' nasa-count-filter-' . $vari_type;
}
$aclass .= $brand_items ? ' nasa-filter-brand-item' : '';
if ($count) {
$hasResult = true;
$var_exist = true;
} elseif (!$count && $hide_empty) {
$class .= ' nasa-empty-hidden';
$show_items = $show_items > 0 ? $show_items += 1 : $show_items;
}
$attr_name = 0 === strpos($term->taxonomy, 'pa_') ? substr($term->taxonomy, 3) : $term->taxonomy;
$attr = esc_attr(sanitize_title($attr_name));
$liClass = ($k % 2 == 0) ? 'nasa-odd' : 'nasa-even';
$liClass .= ' no-hidden';
// $style = ($vari_type == 'color') ? ' style="background:' . esc_attr($term_meta) . '"' : '';
$liClass .= ($show_items > 0 && $k >= $show_items) ? ' nasa-show-less' : '';
$content_li .= '<li class="' . $liClass . $class . ' nasa-attr-' . $attr . ' nasa_' . $attr . '_' . esc_attr($term->term_id) . '">';
$content_li .=
'<a ' .
'class="' . $aclass . '" ' .
'title="' . esc_attr($vari_txt) . '" ' .
'href="' . esc_url($link) . '"' .
'>';
if (($vari_type == 'color')) {
$colors = $term_meta ? explode(',', $term_meta) : array();
$colors = apply_filters('ns_attr_color_arr', $colors);
$color_html = '<span class="nasa-filter-color-span nasa-flex ns-colors-wrap">';
if (isset($colors[0])) {
$color_html .= '<span style="background-color:' . esc_attr($colors[0]) . ';"></span>';
}
if (isset($colors[1])) {
$color_html .= '<span style="background-color:' . esc_attr($colors[1]) . ';"></span>';
}
$color_html .= '</span>';
$content_li .= $color_html;
}
// $content_li .= $vari_type == 'color' ? '<span class="nasa-filter-color-span" ' . $style . '></span>' : '';
if ($vari_type == 'image' && $nasa_attr_ux_exist) {
if (class_exists('Nasa_Abstract_WC_Attr_UX')) {
$image_size = $brand_items ? 'full' : 28;
$img_html = Nasa_Abstract_WC_Attr_UX::get_image_preview($term_meta, false, $image_size, 28, $vari_txt);
} else {
$img_html = wp_get_attachment_image($term_meta, 'thumbnail', false, array('alt' => $vari_txt, 'class' => 'attr-image-preview'));
}
$img_html = $img_html ? $img_html : wc_placeholder_img();
$content_li .= '<span class="nasa-filter-image-span">' . $img_html . '</span>';
}
$content_li .= $content_text;
if (isset($instance['count']) && $instance['count']) {
$content_li .= ' <span class="' . $countClss . '">' . $count . '</span>';
}
$content_li .= '</a>';
$content_li .= '</li>';
}
$hide_widget = !$hasResult && $hide_empty ? true : false;
if (!$hide_widget && !$var_exist) {
$hide_widget = true;
}
if ($hide_widget) {
return array('hide_widget' => $hide_widget, 'content' => '');
}
$content_ul = '<ul class="nasa-variation-filters nasa-variations-' . $vari_type . $class_ul . '">';
$fadeIn = (isset($instance['effect']) && $instance['effect'] == 'fade') ? '1' : '0';
$content_li .= ($show_items && ($count_terms > $show_items)) ?
'<li class="nasa_show_manual" data-fadein="' . $fadeIn . '">' .
'<a data-show="1" class="nasa-show-more" href="javascript:void(0);" data-text="' . esc_attr__('- Show less', 'elessi-theme') . '" rel="nofollow">' .
esc_html__('+ Show more', 'elessi-theme') .
'</a>' .
'</li>' : '';
$content .= $content_ul . $content_li . '</ul></div>';
return array('hide_widget' => $hide_widget, 'content' => $content);
}
return array('hide_widget' => true, 'content' => '');
}
endif;
/**
* Get term count variations
*/
if (!function_exists('elessi_get_filtered_term_product_counts')) :
function elessi_get_filtered_term_product_counts($term_ids, $taxonomy, $query_type) {
if (function_exists('wc_get_container') && class_exists('Automattic\WooCommerce\Internal\ProductAttributesLookup\Filterer')) {
return wc_get_container()->get(Automattic\WooCommerce\Internal\ProductAttributesLookup\Filterer::class)->get_filtered_term_product_counts($term_ids, $taxonomy, $query_type);
}
global $wpdb;
$meta_query = WC_Query::get_main_meta_query();
$tax_query = WC_Query::get_main_tax_query();
if ('or' === $query_type) {
foreach ($tax_query as $key => $query) {
if (isset($query['taxonomy']) && $taxonomy === $query['taxonomy']) {
unset($tax_query[$key]);
}
}
}
$meta_query = new WP_Meta_Query($meta_query);
$tax_query = new WP_Tax_Query($tax_query);
$meta_query_sql = $meta_query->get_sql('post', $wpdb->posts, 'ID');
$tax_query_sql = $tax_query->get_sql($wpdb->posts, 'ID');
// Generate query
$query = array();
$query['select'] = 'SELECT COUNT(DISTINCT ' . $wpdb->posts . '.ID) as term_count, terms.term_id as term_count_id';
$query['from'] = 'FROM ' . $wpdb->posts;
$query['join'] = 'INNER JOIN ' . $wpdb->term_relationships . ' AS term_relationships ON ' . $wpdb->posts . '.ID = term_relationships.object_id ' .
'INNER JOIN ' . $wpdb->term_taxonomy . ' AS term_taxonomy USING(term_taxonomy_id) ' .
'INNER JOIN ' . $wpdb->terms . ' AS terms USING(term_id) ' .
$tax_query_sql['join'] . $meta_query_sql['join'];
$query['where'] = 'WHERE ' . $wpdb->posts . '.post_type LIKE "product" ' .
'AND ' . $wpdb->posts . '.post_status LIKE "publish" ' .
$tax_query_sql['where'] . $meta_query_sql['where'] . ' ' .
'AND terms.term_id IN (' . implode(',', array_map('absint', $term_ids)) . ')';
// For search case
if (isset($_GET['s']) && $_GET['s']) {
$s = esc_sql(str_replace(array("\r", "\n"), '', stripslashes($_GET['s'])));
$query['where'] .= ' AND (' . $wpdb->posts . '.post_title LIKE "%' . $s . '%" OR ' . $wpdb->posts . '.post_excerpt LIKE "%' . $s . '%" OR ' . $wpdb->posts . '.post_content LIKE "%' . $s . '%")';
}
$query['group_by'] = "GROUP BY terms.term_id";
$queryString = implode(' ', apply_filters('woocommerce_get_filtered_term_product_counts_query', $query));
$results = $wpdb->get_results($queryString);
return wp_list_pluck($results, 'term_count', 'term_count_id');
}
endif;
/**
* Return the currently viewed term slug.
* @return int
*/
if (!function_exists('elessi_get_current_term_slug')) :
function elessi_get_current_term_slug() {
return absint(is_tax() ? get_queried_object()->slug : 0);
}
endif;
/**
* Get current page URL for layered nav items.
* @return string
*/
if (!function_exists('elessi_get_page_base_url')) :
function elessi_get_page_base_url($taxonomy) {
if (defined('SHOP_IS_ON_FRONT')) {
$link = home_url('/');
} elseif (is_post_type_archive('product') || is_page(wc_get_page_id('shop'))) {
$link = get_post_type_archive_link('product');
} elseif (is_product_category()) {
$link = get_term_link(get_query_var('product_cat'), 'product_cat');
} elseif (is_product_tag()) {
$link = get_term_link(get_query_var('product_tag'), 'product_tag');
} else {
$queried_object = get_queried_object();
$link = get_term_link($queried_object, $queried_object->taxonomy);
}
/**
* Custom taxonomy
*/
if (class_exists('Nasa_WC_Taxonomy')) {
$nasa_taxonomy = apply_filters('nasa_taxonomy_custom_cateogory', Nasa_WC_Taxonomy::$nasa_taxonomy);
if (isset($_GET[$nasa_taxonomy])) {
$link = add_query_arg($nasa_taxonomy, wc_clean(wp_unslash($_GET[$nasa_taxonomy])), $link);
}
}
/**
* Min
*/
if (isset($_GET['min_price'])) {
$link = add_query_arg('min_price', wc_clean(wp_unslash($_GET['min_price'])), $link);
}
/**
* Max
*/
if (isset($_GET['max_price'])) {
$link = add_query_arg('max_price', wc_clean(wp_unslash($_GET['max_price'])), $link);
}
/**
* Orderby
*/
if (isset($_GET['orderby'])) {
$link = add_query_arg('orderby', wc_clean(wp_unslash($_GET['orderby'])), $link);
}
/**
* Search Arg.
* To support quote characters, first they are decoded from &quot; entities, then URL encoded.
*/
if (get_search_query()) {
$link = add_query_arg('s', rawurlencode(wp_specialchars_decode(get_search_query())), $link);
}
/**
* Post Type Arg
*/
if (isset($_GET['post_type'])) {
$link = add_query_arg('post_type', wc_clean(wp_unslash($_GET['post_type'])), $link);
/**
* Prevent post type and page id when pretty permalinks are disabled.
*/
if (is_shop()) {
$link = remove_query_arg('page_id', $link);
}
}
/**
* Min Rating Arg
*/
if (isset($_GET['rating_filter'])) {
$link = add_query_arg('rating_filter', wc_clean(wp_unslash($_GET['rating_filter'])), $link);
}
/**
* Filter Status
*/
if (class_exists('Elessi_WC_Widget_Status_Filter')) {
foreach (Elessi_WC_Widget_Status_Filter::$_status as $status) {
if (isset($_GET[$status]) && $_GET[$status] === '1') {
$link = add_query_arg($status, '1', $link);
}
}
}
/**
* Filter Alphabet
*/
if (class_exists('Elessi_WC_Widget_Alphabet_Filter')) {
$alpha_rq = Elessi_WC_Widget_Alphabet_Filter::$_request_name;
if (isset($_GET[$alpha_rq]) && in_array($_GET[$alpha_rq], Elessi_WC_Widget_Alphabet_Filter::$_alphabet)) {
$link = add_query_arg($alpha_rq, wc_clean(wp_unslash($_GET[$alpha_rq])), $link);
}
}
/**
* Filter Multi Tags
*/
if (class_exists('Elessi_WC_Widget_Tags_Filter')) {
if (isset($_GET[Elessi_WC_Widget_Tags_Filter::$_request_name]) && !empty($_GET[Elessi_WC_Widget_Tags_Filter::$_request_name])) {
$link = add_query_arg(Elessi_WC_Widget_Tags_Filter::$_request_name, wc_clean(wp_unslash($_GET[Elessi_WC_Widget_Tags_Filter::$_request_name])), $link);
}
}
/**
* Filter Multi Categories
*/
if (class_exists('Elessi_WC_Widget_Multi_Categories_Filter')) {
if (isset($_GET[Elessi_WC_Widget_Multi_Categories_Filter::$_request_name]) && !empty($_GET[Elessi_WC_Widget_Multi_Categories_Filter::$_request_name])) {
$link = add_query_arg(Elessi_WC_Widget_Multi_Categories_Filter::$_request_name, wc_clean(wp_unslash($_GET[Elessi_WC_Widget_Multi_Categories_Filter::$_request_name])), $link);
}
}
/**
* All current filters
*/
if ($_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes()) {
$taxonomy = wc_attribute_taxonomy_slug($taxonomy);
foreach ($_chosen_attributes as $name => $data) {
$filter_name = wc_attribute_taxonomy_slug($name);
if ($taxonomy == $filter_name) {
continue;
}
if (!empty($data['terms'])) {
$link = add_query_arg('filter_' . $filter_name, implode(',', $data['terms']), $link);
}
if ('or' === $data['query_type']) {
$link = add_query_arg('query_type_' . $filter_name, 'or', $link);
}
}
}
return apply_filters('nasa_page_base_url', $link);
}
endif;
/**
* Get current page URL Origin Not Request GET.
* @return string
*/
if (!function_exists('elessi_get_origin_url')) :
function elessi_get_origin_url($remove_query = array('page', 'paged', 'product-page')) {
global $wp;
$nasa_origin_url = get_option('permalink_structure') == '' ?
remove_query_arg($remove_query, add_query_arg($wp->query_string, '', home_url(trailingslashit($wp->request)))) :
preg_replace('%\/page/[0-9]+%', '', home_url(trailingslashit($wp->request)));
return apply_filters('nasa_origin_url', $nasa_origin_url);
}
endif;
/**
* Get current page URL Origin Not Request GET But Has Paged.
* @return string
*/
if (!function_exists('elessi_get_origin_url_paging')) :
function elessi_get_origin_url_paging($exc = array()) {
global $wp, $nasa_origin_url_paging;
if (!isset($nasa_origin_url_paging)) {
$nasa_origin_url_paging = get_option('permalink_structure') == '' ?
add_query_arg($wp->query_string, '', home_url(trailingslashit($wp->request))) :
home_url(trailingslashit($wp->request));
$GLOBALS['nasa_origin_url_paging'] = $nasa_origin_url_paging;
}
/**
* Exclude
*/
if (!empty($exc)) {
foreach ($exc as $get) {
if (isset($_GET[$get])) {
$nasa_origin_url_paging = add_query_arg($get, esc_attr($_GET[$get]), $nasa_origin_url_paging);
}
}
}
return apply_filters('nasa_origin_url_paging', $nasa_origin_url_paging);
}
endif;
/**
* Remove defaults widgets of Woocommerce
*/
// add_action('init', 'elessi_remove_default_wg_woo');
if (!function_exists('elessi_remove_default_wg_woo')) :
function elessi_remove_default_wg_woo() {
global $nasa_opt;
if ((!isset($nasa_opt['disable_ajax_product']) || !$nasa_opt['disable_ajax_product'])) {
unregister_widget('WC_Widget_Price_Filter');
unregister_widget('WC_Widget_Layered_Nav');
unregister_widget('WC_Widget_Layered_Nav_Filters');
unregister_widget('WC_Widget_Rating_Filter');
unregister_widget('WC_Widget_Product_Search');
}
}
endif;
+383
View File
@@ -0,0 +1,383 @@
<?php
defined('ABSPATH') or die(); // Exit if accessed directly
/**
* Nasa Wishlist
*
* Since 3.0
*/
if (!NASA_WISHLIST_ENABLE && NASA_WOO_ACTIVED) :
class ELESSI_WOO_WISHLIST {
/**
* instance of the class
*/
protected static $instance = null;
/**
* Support multi Languages
*/
protected $multi_langs = false;
/**
* Current Language
*/
public $current_lang = '';
/**
* List Languages
*/
public $languages = array();
/**
* Cookie name
*/
public $cookie_name = 'nasa_wishlist';
/**
* wishlist_list
*/
public $wishlist_list = array();
/**
* expire time
*/
public $expire = 0;
/**
* Init Class
*/
public static function init() {
global $nasa_opt;
if (isset($nasa_opt['enable_nasa_wishlist']) && !$nasa_opt['enable_nasa_wishlist']) {
return null;
}
if (null == self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor.
*/
public function __construct() {
global $nasa_opt;
$in_mobile = isset($nasa_opt['nasa_in_mobile']) && $nasa_opt['nasa_in_mobile'] ? true : false;
$mobile_app = $in_mobile && isset($nasa_opt['mobile_layout']) && $nasa_opt['mobile_layout'] == 'app' ? true : false;
$siteurl = get_option('siteurl');
$this->cookie_name .= $siteurl ? '_' . md5($siteurl) : '';
$this->current_lang = defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : get_option('WPLANG');
if (trim($this->current_lang) == '') {
$this->current_lang = 'default';
}
$this->languages = array($this->current_lang);
/**
* Support Multi Languages
*/
if (function_exists('icl_get_languages')) {
$this->multi_langs = true;
$wpml_langs = icl_get_languages('skip_missing=0&orderby=code');
if (!empty($wpml_langs)) {
foreach ($wpml_langs as $lang) {
if (isset($lang['language_code']) && !in_array($lang['language_code'], $this->languages)) {
$this->languages[] = $lang['language_code'];
}
}
}
}
$this->wishlist_list = $this->get_wishlist_list();
/**
* Live 30 days
*/
$this->expire = apply_filters('nasa_cookie_wishlist_live', NASA_TIME_NOW + (60 * 60 * 24 * 30));
add_action('nasa_show_buttons_loop', array($this, 'btn_in_list'), 20);
if ($mobile_app) {
add_action('woocommerce_single_product_summary', array($this, 'btn_wishlist_with_label'), 31);
} else {
add_action('nasa_single_buttons', array($this, 'btn_in_detail'), 10);
}
}
/**
* get Cookie Name
*
* @return type
*/
public function get_cookie_name($_lang = null) {
$lang = !$_lang ? $this->current_lang : $_lang;
return $this->cookie_name . '_' . $lang;
}
/**
* Get Wishlist items id
*/
public function get_wishlist_list($_lang = null) {
$wishlists = isset($_COOKIE[$this->get_cookie_name($_lang)]) ? json_decode($_COOKIE[$this->get_cookie_name($_lang)]) : array();
if (!is_array($wishlists)) {
$wishlists = array();
}
return $wishlists;
}
/**
* Get Wishlist items id of Current language
*/
public function get_current_wishlist() {
return $this->wishlist_list;
}
/**
* btn wishlist with label
*
* @global type $product
*/
public function btn_wishlist_with_label() {
global $product;
if (!$product) {
return;
}
$variation = false;
$productId = $product->get_id();
$productType = $product->get_type();
if ($productType == 'variation') {
$variation_product = $product;
$productId = wp_get_post_parent_id($productId);
$parentProduct = wc_get_product($productId);
$productType = $parentProduct->get_type();
$GLOBALS['product'] = $parentProduct;
$variation = true;
}
$class_btn = 'btn-wishlist btn-link wishlist-icon btn-nasa-wishlist nasa-flex ns-has-wrap';
?>
<a href="javascript:void(0);" class="<?php echo esc_attr($class_btn); ?>" data-prod="<?php echo (int) $productId; ?>" data-prod_type="<?php echo esc_attr($productType); ?>" title="<?php esc_attr_e('Wishlist', 'elessi-theme'); ?>" rel="nofollow">
<svg class="nasa-icon ns-stroke" width="20" height="20" viewBox="0 0 32 32">
<path d="M21.886 5.115c3.521 0 6.376 2.855 6.376 6.376 0 1.809-0.754 3.439-1.964 4.6l-10.297 10.349-10.484-10.536c-1.1-1.146-1.778-2.699-1.778-4.413 0-3.522 2.855-6.376 6.376-6.376 2.652 0 4.925 1.62 5.886 3.924 0.961-2.304 3.234-3.924 5.886-3.924zM21.886 4.049c-2.345 0-4.499 1.089-5.886 2.884-1.386-1.795-3.54-2.884-5.886-2.884-4.104 0-7.442 3.339-7.442 7.442 0 1.928 0.737 3.758 2.075 5.152l11.253 11.309 11.053-11.108c1.46-1.402 2.275-3.308 2.275-5.352 0-4.104-3.339-7.442-7.442-7.442v0z" fill="currentColor" />
</svg>
<svg class="nasa-icon ns-filled" width="20" height="20" viewBox="0 0 28 32">
<path d="M19.886 4.049c-2.345 0-4.499 1.089-5.886 2.884-1.386-1.795-3.54-2.884-5.886-2.884-4.104 0-7.442 3.339-7.442 7.442 0 1.928 0.737 3.758 2.075 5.152l11.253 11.309 11.053-11.108c1.46-1.402 2.275-3.308 2.275-5.352 0-4.104-3.339-7.442-7.442-7.442z" fill="currentColor" />
</svg>
<span class="nasa-icon-text-wrap">
<span class="margin-left-5 rtl-margin-left-0 rtl-margin-right-5 nasa-icon-text"><?php echo esc_html__('Add to wishlist', 'elessi-theme'); ?></span>
<span class="margin-left-5 rtl-margin-left-0 rtl-margin-right-5 nasa-icon-text"><?php echo esc_html__('Added to wishlist', 'elessi-theme'); ?></span>
</span>
</a>
<?php
if ($variation) {
$GLOBALS['product'] = $variation_product;
}
}
/**
* btn wishlist in list
*
* @global type $product
*/
public function btn_wishlist($tip = 'left') {
global $product;
if (!$product) {
return;
}
$variation = false;
$productId = $product->get_id();
$productType = $product->get_type();
if ($productType == 'variation') {
$variation_product = $product;
$productId = wp_get_post_parent_id($productId);
$parentProduct = wc_get_product($productId);
$productType = $parentProduct->get_type();
$GLOBALS['product'] = $parentProduct;
$variation = true;
}
$class_btn = 'btn-wishlist btn-link wishlist-icon btn-nasa-wishlist nasa-tip';
$class_btn .= ' nasa-tip-' . $tip;
?>
<a href="javascript:void(0);" class="<?php echo esc_attr($class_btn); ?>" data-prod="<?php echo (int) $productId; ?>" data-prod_type="<?php echo esc_attr($productType); ?>" data-icon-text="<?php esc_attr_e('Add to Wishlist', 'elessi-theme'); ?>" data-added="<?php esc_attr_e('Added to Wishlist', 'elessi-theme'); ?>" title="<?php esc_attr_e('Wishlist', 'elessi-theme'); ?>" rel="nofollow">
<svg class="nasa-icon ns-stroke" width="20" height="20" viewBox="0 0 32 32">
<path d="M21.886 5.115c3.521 0 6.376 2.855 6.376 6.376 0 1.809-0.754 3.439-1.964 4.6l-10.297 10.349-10.484-10.536c-1.1-1.146-1.778-2.699-1.778-4.413 0-3.522 2.855-6.376 6.376-6.376 2.652 0 4.925 1.62 5.886 3.924 0.961-2.304 3.234-3.924 5.886-3.924zM21.886 4.049c-2.345 0-4.499 1.089-5.886 2.884-1.386-1.795-3.54-2.884-5.886-2.884-4.104 0-7.442 3.339-7.442 7.442 0 1.928 0.737 3.758 2.075 5.152l11.253 11.309 11.053-11.108c1.46-1.402 2.275-3.308 2.275-5.352 0-4.104-3.339-7.442-7.442-7.442v0z" fill="currentColor" />
</svg>
<svg class="nasa-icon ns-filled" width="20" height="20" viewBox="0 0 28 32">
<path d="M19.886 4.049c-2.345 0-4.499 1.089-5.886 2.884-1.386-1.795-3.54-2.884-5.886-2.884-4.104 0-7.442 3.339-7.442 7.442 0 1.928 0.737 3.758 2.075 5.152l11.253 11.309 11.053-11.108c1.46-1.402 2.275-3.308 2.275-5.352 0-4.104-3.339-7.442-7.442-7.442z" fill="currentColor" />
</svg>
</a>
<?php
if ($variation) {
$GLOBALS['product'] = $variation_product;
}
}
/**
* btn wishlist in list
*
* @global type $product
*/
public function btn_in_list() {
$this->btn_wishlist('left');
}
/**
* btn wishlist in detail
*
* @global type $product
*/
public function btn_in_detail() {
$this->btn_wishlist('right');
}
/**
* Add Wishlist
*/
public function add_to_wishlist($_product_id) {
$product_id = intval($_product_id);
if (!$product_id) {
return false;
}
if ($this->languages) {
foreach ($this->languages as $lang) {
$wishlists = $this->get_wishlist_list($lang);
if ($this->current_lang == $lang) {
$wishlists[] = $product_id;
$this->wishlist_list = $wishlists;
}
/**
* Support Multi Languages
*/
else {
if ($this->multi_langs) {
$product_langID = icl_object_id($product_id, 'product', true, $lang);
$wishlists[] = $product_langID;
}
}
$this->set_cookie_wishlist($lang, $wishlists);
}
}
return true;
}
/**
* Remove from Wishlist
*/
public function remove_from_wishlist($_product_id) {
$product_id = intval($_product_id);
if (!$product_id) {
return false;
}
if ($this->languages) {
foreach ($this->languages as $lang) {
if ($this->current_lang == $lang) {
$wishlists = $this->wishlist_list;
if ($wishlists) {
foreach ($wishlists as $k => $v) {
if ($v == $product_id) {
unset($wishlists[$k]);
}
}
}
$this->wishlist_list = $wishlists;
}
/**
* Support WPML
*/
else {
$wishlists = $this->get_wishlist_list($lang);
if ($this->multi_langs) {
if ($wishlists) {
$product_langID = icl_object_id($product_id, 'product', true, $lang);
foreach ($wishlists as $k => $v) {
if ($v == $product_langID) {
unset($wishlists[$k]);
}
}
}
}
}
$this->set_cookie_wishlist($lang, $wishlists);
}
}
return true;
}
/**
* Count wishlist items
*
* @return type
*/
public function count_items() {
return count($this->wishlist_list);
}
/**
* Set cookie wishlist
*/
protected function set_cookie_wishlist($lang = null, $wishlists = array()) {
setcookie($this->get_cookie_name($lang), json_encode(array_values($wishlists)), $this->expire, COOKIEPATH, COOKIE_DOMAIN, false, false);
}
/**
* Wishlist html
*/
public function wishlist_html() {
global $nasa_opt;
$wishlist_items = $this->wishlist_list;
$file = ELESSI_CHILD_PATH . '/includes/nasa-sidebar-wishlist_html.php';
include is_file($file) ? $file : ELESSI_THEME_PATH . '/includes/nasa-sidebar-wishlist_html.php';
}
}
/**
* Init NasaTheme Wishlist
*/
add_action('init', 'elessi_woo_wishlist');
if (!function_exists('elessi_woo_wishlist')) :
function elessi_woo_wishlist() {
return ELESSI_WOO_WISHLIST::init();
}
endif;
endif;
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+493
View File
@@ -0,0 +1,493 @@
<?php
defined('ABSPATH') or die(); // Exit if accessed directly
/**
* Compatible with Yith WooCommerce Wishlist
*/
if (NASA_WISHLIST_ENABLE && class_exists('YITH_WCWL_Shortcode')) :
class ELESSI_YITH_WCWL_Shortcode extends YITH_WCWL_Shortcode {
/**
* Init Class
*/
public static function init() {
if (!NASA_WISHLIST_NEW_VER) {
add_shortcode('nasa_yith_wcwl_wishlist', array('ELESSI_YITH_WCWL_Shortcode', 'wishlist'));
} else {
add_shortcode('nasa_yith_wcwl_wishlist', array('ELESSI_YITH_WCWL_Shortcode', 'wishlist_new'));
}
add_filter('yith_wcwl_localize_script', array('ELESSI_YITH_WCWL_Shortcode', 'nasa_yith_wcwl_localize_script'));
}
/**
*
* @param type $localize_script
* @return type
*/
public static function nasa_yith_wcwl_localize_script($localize_script) {
if (isset($localize_script['labels']['added_to_cart_message'])) {
$localize_script['labels']['added_to_cart_message'] = sprintf(
'<div class="woocommerce-message text-center" role="alert">%s</div>',
apply_filters(
'yith_wcwl_added_to_cart_message',
esc_html__('Product added to cart successfully!', 'elessi-theme')
)
);
}
return $localize_script;
}
/**
* Wishlist Sidebar OLD Version 2.x
*/
public static function wishlist($atts = array(), $content = null) {
global $yith_wcwl_is_wishlist, $yith_wcwl_wishlist_token;
$atts = shortcode_atts(array(
'per_page' => 5,
// 'pagination' => 'no',
'wishlist_id' => false,
'action_params' => get_query_var(YITH_WCWL()->wishlist_param, false)
), $atts);
$available_views = apply_filters('yith_wcwl_available_wishlist_views', array('view', 'user'));
extract($atts);
$pagination = 'no';
// retrieve options from query string
$action_params = explode('/', apply_filters('yith_wcwl_current_wishlist_view_params', $action_params));
$action = (isset($action_params[0])) ? $action_params[0] : 'view';
$user_id = isset($_GET['user_id']) ? $_GET['user_id'] : false;
// init params needed to load correct tempalte
$additional_params = array();
$template_part = 'view';
/* === WISHLIST TEMPLATE === */
if (
empty($action) ||
(!empty($action) && ( $action == 'view' || $action == 'user' ) ) ||
(!empty($action) && ( $action == 'manage' || $action == 'create' ) && get_option('yith_wcwl_multi_wishlist_enable', false) != 'yes' ) ||
(!empty($action) && !in_array($action, $available_views) ) ||
!empty($user_id)
) {
/*
* someone is requesting a wishlist
* -if user is not logged in..
* -and no wishlist_id is passed, cookie wishlist is loaded
* -and a wishlist_id is passed, checks if wishlist is public or shared, and shows it only in this case
* -if user is logged in..
* -and no wishlist_id is passed, default wishlist is loaded
* -and a wishlist_id is passed, checks owner of the wishlist
* -if wishlist is of the logged user, shows it
* -if wishlist is of another user, checks if wishlist is public or shared, and shows it only in this case (if user is admin, can see all wishlists)
*/
if (empty($wishlist_id)) {
if (!empty($action) && $action == 'user') {
$user_id = isset($action_params[1]) ? $action_params[1] : false;
$user_id = (!$user_id) ? get_query_var($user_id, false) : $user_id;
$user_id = (!$user_id) ? get_current_user_id() : $user_id;
$wishlists = YITH_WCWL()->get_wishlists(array('user_id' => $user_id, 'is_default' => 1));
if (!empty($wishlists) && isset($wishlists[0])) {
$wishlist_id = $wishlists[0]['wishlist_token'];
} else {
$wishlist_id = false;
}
} else {
$wishlist_id = isset($action_params[1]) ? $action_params[1] : false;
$wishlist_id = (!$wishlist_id) ? get_query_var('wishlist_id', false) : $wishlist_id;
}
}
$is_user_owner = false;
$query_args = array();
if (!empty($user_id)) {
$query_args['user_id'] = $user_id;
$query_args['is_default'] = 1;
if (get_current_user_id() == $user_id) {
$is_user_owner = true;
}
} elseif (!NASA_CORE_USER_LOGGED) {
if (empty($wishlist_id)) {
$query_args['wishlist_id'] = false;
$is_user_owner = true;
} else {
$is_user_owner = false;
$query_args['wishlist_token'] = $wishlist_id;
$query_args['wishlist_visibility'] = 'visible';
}
} else {
if (empty($wishlist_id)) {
$query_args['user_id'] = get_current_user_id();
$query_args['is_default'] = 1;
$is_user_owner = true;
} else {
$wishlist = YITH_WCWL()->get_wishlist_detail_by_token($wishlist_id);
$is_user_owner = $wishlist['user_id'] == get_current_user_id();
$query_args['wishlist_token'] = $wishlist_id;
if (!empty($wishlist) && $wishlist['user_id'] != get_current_user_id()) {
$query_args['user_id'] = false;
if (!current_user_can(apply_filters('yith_wcwl_view_wishlist_capability', 'manage_options'))) {
$query_args['wishlist_visibility'] = 'visible';
}
}
}
}
// counts number of elements in wishlist for the user
$count = YITH_WCWL()->count_products($wishlist_id);
// sets current page, number of pages and element offset
$current_page = max(1, get_query_var('paged'));
// sets variables for pagination, if shortcode atts is set to yes
if ($pagination == 'yes' && $count > 1) {
$pages = ceil($count / $per_page);
if ($current_page > $pages) {
$current_page = $pages;
}
$offset = ($current_page - 1) * $per_page;
if ($pages > 1) {
$page_links = paginate_links(array(
'base' => esc_url(add_query_arg(array('paged' => '%#%'), YITH_WCWL()->get_wishlist_url('view' . '/' . $wishlist_id))),
'format' => '?paged=%#%',
'current' => $current_page,
'total' => $pages,
'show_all' => true
));
}
$query_args['limit'] = $per_page;
$query_args['offset'] = $offset;
}
if (empty($wishlist_id) && NASA_CORE_USER_LOGGED) {
$wishlists = YITH_WCWL()->get_wishlists(array('user_id' => get_current_user_id(), 'is_default' => 1));
if (!empty($wishlists)) {
$wishlist_id = $wishlists[0]['wishlist_token'];
}
}
$yith_wcwl_wishlist_token = $wishlist_id;
// retrieve items to print
$wishlist_items = YITH_WCWL()->get_products($query_args);
// retrieve wishlist information
$wishlist_meta = YITH_WCWL()->get_wishlist_detail_by_token($wishlist_id);
$is_default = $wishlist_meta['is_default'] == 1;
$wishlist_token = !empty($wishlist_meta['wishlist_token']) ? $wishlist_meta['wishlist_token'] : false;
// retireve wishlist title
$default_wishlist_title = get_option('yith_wcwl_wishlist_title');
$wishlist_title = $is_default ? $default_wishlist_title : $wishlist_meta['wishlist_name'];
// retrieve estimate options
$show_ask_estimate_button = get_option('yith_wcwl_show_estimate_button') == 'yes';
$ask_estimate_url = false;
if ($show_ask_estimate_button) {
$ask_estimate_url = esc_url(wp_nonce_url(
add_query_arg(
'ask_an_estimate', !empty($wishlist_token) ? $wishlist_token : 'false', YITH_WCWL()->get_wishlist_url('view' . (!$is_default ? '/' . $wishlist_token : '' ))
), 'ask_an_estimate', 'estimate_nonce'
));
}
$show_date_added = get_option('yith_wcwl_show_dateadded') == 'yes';
$show_add_to_cart = get_option('yith_wcwl_add_to_cart_show' ) == 'yes';
$additional_params = array(
// wishlist items
'count' => $count,
'wishlist_items' => $wishlist_items,
// wishlist data
'wishlist_meta' => $wishlist_meta,
'is_default' => $is_default,
'is_custom_list' => !$is_default && $is_user_owner,
'wishlist_token' => $wishlist_token,
'wishlist_id' => $wishlist_meta['ID'],
'is_private' => $wishlist_meta['wishlist_privacy'] == 2,
//page data
'page_title' => $wishlist_title,
'default_wishlsit_title' => $default_wishlist_title,
'current_page' => $current_page,
'page_links' => isset($page_links) ? $page_links : false,
// user data
'is_user_logged_in' => NASA_CORE_USER_LOGGED,
'is_user_owner' => $is_user_owner,
// view data
'show_price' => get_option('yith_wcwl_price_show') == 'yes',
'show_dateadded' => $show_date_added,
'show_ask_estimate_button' => $show_ask_estimate_button,
'ask_estimate_url' => $ask_estimate_url,
'show_stock_status' => get_option('yith_wcwl_stock_show') == 'yes',
'show_add_to_cart' => $show_add_to_cart,
'add_to_cart_text' => get_option('yith_wcwl_add_to_cart_text'),
'price_excl_tax' => get_option('woocommerce_tax_display_cart') == 'excl',
'show_cb' => false,
// template data
'template_part' => $template_part,
'additional_info' => false,
'available_multi_wishlist' => false,
'users_wishlists' => array(),
'form_action' => esc_url(YITH_WCWL()->get_wishlist_url('view' . (!$is_default ? '/' . $wishlist_token : '' )))
);
}
$additional_params = apply_filters('yith_wcwl_wishlist_params', $additional_params, $action, $action_params, $pagination, $per_page, $atts);
$additional_params['template_part'] = isset($additional_params['template_part']) ? $additional_params['template_part'] : $template_part;
$atts = array_merge($atts, $additional_params);
extract($atts);
// sets that we're in the wishlist template
$yith_wcwl_is_wishlist = true;
ob_start();
$template = ELESSI_CHILD_PATH . '/includes/nasa-sidebar-wishlist_content.php';
include is_file($template) ? $template : ELESSI_THEME_PATH . '/includes/nasa-sidebar-wishlist_content.php';
$content_wishlist = ob_get_clean();
// we're not in wishlist template anymore
$yith_wcwl_is_wishlist = false;
$yith_wcwl_wishlist_token = null;
return apply_filters('nasa_yith_wcwl_wishlisth_html', $content_wishlist, array(), true);
}
/**
* For Yith_WooCommerce_Wishlist 3.0 or Higher
*/
public static function wishlist_new($atts = array(), $content = null) {
global $yith_wcwl_is_wishlist, $yith_wcwl_wishlist_token;
$atts = shortcode_atts(array(
'per_page' => 5,
'wishlist_id' => false,
'action_params' => get_query_var(YITH_WCWL()->wishlist_param, false),
'no_interactions' => 'no',
'layout' => ''
), $atts);
/**
* @var $per_page int
* @var $wishlist_id int
* @var $action_params array
* @var $no_interactions string
* @var $layout string
*/
extract($atts);
$pagination = 'no';
// retrieve options from query string
$action_params = explode('/', apply_filters('yith_wcwl_current_wishlist_view_params', $action_params));
$action = (isset($action_params[0])) ? $action_params[0] : 'view';
// retrieve options from db
$default_wishlist_title = get_option('yith_wcwl_wishlist_title');
$show_price = get_option('yith_wcwl_price_show') == 'yes';
$show_stock = get_option('yith_wcwl_stock_show') == 'yes';
$show_date_added = get_option('yith_wcwl_show_dateadded') == 'yes';
$show_add_to_cart = get_option('yith_wcwl_add_to_cart_show') == 'yes';
$show_remove_product = get_option('yith_wcwl_show_remove', 'yes') == 'yes';
$show_variation = get_option('yith_wcwl_variation_show') == 'yes';
$repeat_remove_button = get_option('yith_wcwl_repeat_remove_button') == 'yes';
$add_to_cart_label = get_option('yith_wcwl_add_to_cart_text', __('Add to cart', 'elessi-theme'));
$price_excluding_tax = get_option('woocommerce_tax_display_cart') == 'excl';
$ajax_loading = get_option('yith_wcwl_ajax_enable', 'no');
// icons
$icon = get_option('yith_wcwl_add_to_wishlist_icon');
$custom_icon = get_option('yith_wcwl_add_to_wishlist_custom_icon');
if ('custom' == $icon){
$heading_icon = '<img src="' . $custom_icon . '" width="32" />';
}
else {
$heading_icon = !empty($icon) ? '<i class="fa ' . $icon . '"></i>' : '';
}
// init params needed to load correct template
$template_part = 'view';
$no_interactions = $no_interactions == 'yes';
$additional_params = array(
// wishlist data
'wishlist' => false,
'is_default' => true,
'is_custom_list' => false,
'wishlist_token' => '',
'wishlist_id' => false,
'is_private' => false,
// wishlist items
'count' => 0,
'wishlist_items' => array(),
//page data
'page_title' => $default_wishlist_title,
'default_wishlsit_title' => $default_wishlist_title,
'current_page' => 1,
'page_links' => false,
'layout' => $layout,
// user data
'is_user_logged_in' => NASA_CORE_USER_LOGGED,
'is_user_owner' => true,
// view data
'no_interactions' => $no_interactions,
'show_price' => $show_price,
'show_dateadded' => $show_date_added,
'show_stock_status' => $show_stock,
'show_add_to_cart' => $show_add_to_cart && !$no_interactions,
'show_remove_product' => $show_remove_product && !$no_interactions,
'add_to_cart_text' => $add_to_cart_label,
'show_ask_estimate_button' => false,
'ask_estimate_url' => '',
'price_excl_tax' => $price_excluding_tax,
'show_cb' => false,
'show_quantity' => false,
'show_variation' => $show_variation,
'show_price_variations' => false,
'show_update' => false,
'enable_drag_n_drop' => false,
'enable_add_all_to_cart' => false,
'move_to_another_wishlist' => false,
// wishlist icon
'heading_icon' => $heading_icon,
// share data
'share_enabled' => false,
// template data
'template_part' => $template_part,
'additional_info' => false,
'available_multi_wishlist' => false,
'users_wishlists' => array(),
'form_action' => esc_url(YITH_WCWL()->get_wishlist_url('view'))
);
$wishlist = YITH_WCWL_Wishlist_Factory::get_current_wishlist($atts);
if ($wishlist){
// set global wishlist token
$yith_wcwl_wishlist_token = $wishlist->get_token();
// retrieve wishlist params
$is_user_owner = $wishlist->is_current_user_owner();
$count = $wishlist->count_items();
$offset = 0;
// sets current page, number of pages and element offset
$current_page = max(1, get_query_var('paged'));
// sets variables for pagination, if shortcode atts is set to yes
if ($pagination == 'yes' && ! $no_interactions && $count > 1){
$pages = ceil($count / $per_page);
if ($current_page > $pages){
$current_page = $pages;
}
$offset = ($current_page - 1) * $per_page;
if ($pages > 1){
$page_links = paginate_links(array(
'base' => esc_url(add_query_arg(array('paged' => '%#%'), $wishlist->get_url())),
'format' => '?paged=%#%',
'current' => $current_page,
'total' => $pages,
'show_all' => true
));
}
}
else{
$per_page = 0;
}
// retrieve items to print
$wishlist_items = $wishlist->get_items($per_page, $offset);
// retrieve wishlist information
$is_default = $wishlist->get_is_default();
$wishlist_token = $wishlist->get_token();
$wishlist_title = $wishlist->get_formatted_name();
$additional_params = wp_parse_args(array(
// wishlist items
'count' => $count,
'wishlist_items' => $wishlist_items,
// wishlist data
'wishlist' => $wishlist,
'is_default' => $is_default,
'is_custom_list' => $is_user_owner && ! $no_interactions,
'wishlist_token' => $wishlist_token,
'wishlist_id' => $wishlist->get_id(),
'is_private' => $wishlist->get_privacy() == 2,
'ajax_loading' => $ajax_loading,
//page data
'page_title' => $wishlist_title,
'current_page' => $current_page,
'page_links' => isset($page_links) && !$no_interactions ? $page_links : false,
// user data
'is_user_owner' => $is_user_owner,
// view data
'show_remove_product' => $show_remove_product && $is_user_owner && ! $no_interactions,
'repeat_remove_button' => $repeat_remove_button && $is_user_owner && ! $no_interactions,
// template data
'form_action' => $wishlist->get_url()
), $additional_params);
}
// filter params
$additional_params = apply_filters('yith_wcwl_wishlist_params', $additional_params, $action, $action_params, $pagination, $per_page, $atts);
$atts = array_merge(
$atts,
$additional_params
);
$atts['fragment_options'] = YITH_WCWL_Frontend()->format_fragment_options($atts, 'wishlist');
extract($atts);
ob_start();
$template = ELESSI_CHILD_PATH . '/includes/nasa-sidebar-wishlist_content.php';
include is_file($template) ? $template : ELESSI_THEME_PATH . '/includes/nasa-sidebar-wishlist_content.php';
$content_wishlist = ob_get_clean();
return apply_filters('nasa_yith_wcwl_wishlisth_html', $content_wishlist, array(), true);
}
}
ELESSI_YITH_WCWL_Shortcode::init();
endif;