aliceevra
Forum Replies Created
-
Hi , this is the code
public static function get_filtered_price($additional_taxes = “”) {
global $wpdb, $wp_the_query, $WOOF;// Check if the user is logged in and has the 'pro' role
$user_is_pro = is_user_logged_in() && current_user_can('pro'); // Adjust 'pro' to the correct user role or custom condition
$args = $wp_the_query->query_vars;
$tax_query = isset($args['tax_query']) ? $args['tax_query'] : array();
if (is_object($wp_the_query->tax_query)) {
$tax_query = $wp_the_query->tax_query->queries; //fix for cat page
}
$meta_query = isset($args['meta_query']) ? $args['meta_query'] : array();
// Adapt tax query for additional taxes
$tax_query = woof()->get_tax_query($additional_taxes);
// Get the current taxonomy term
$current_term = woof()->get_really_current_term();
if (!empty($current_term)) {
$tax_query[] = array(
'taxonomy' => $current_term->taxonomy,
'field' => 'slug', //id
'terms' => $current_term->slug
);
}
// Handle cases with more than one taxonomy
$temp_arr = array();
if (isset($args['taxonomy']) AND isset($args[$args['taxonomy']]) AND !empty($args[$args['taxonomy']])) {
$temp_arr = explode(',', $args[$args['taxonomy']]);
if (!$temp_arr OR count($temp_arr) < 1) {
$temp_arr = array();
}
}
// Apply taxonomy filters
if (!empty($args['taxonomy']) && !empty($args['term'])) {
$tax_query[] = array(
'taxonomy' => $args['taxonomy'],
'terms' => (empty($temp_arr)) ? array($args['term']) : $temp_arr,
'field' => 'slug',
);
}
// Exclude price and rating filters from meta query
if (!empty($meta_query) AND is_array($meta_query)) {
foreach ($meta_query as $key => $query) {
if (!empty($query['price_filter']) || !empty($query['rating_filter'])) {
unset($meta_query[$key]);
}
}
}
// Create meta and taxonomy queries
$meta_query = new WP_Meta_Query($meta_query);
$tax_query = new WP_Tax_Query($tax_query);
// Generate SQL for meta and tax queries
$meta_query_sql = $meta_query->get_sql('post', $wpdb->posts, 'ID');
$tax_query_sql = $tax_query->get_sql($wpdb->posts, 'ID');
// Check whether to use the 'prix_profesionnel' meta key for pro users
$price_meta_key = $user_is_pro ? '_prix_profesionnel' : '_price';
// Build SQL query
$sql = "SELECT min( FLOOR( price_meta.meta_value + 0.0) ) as min_price, max( CEILING( price_meta.meta_value + 0.0) ) as max_price
FROM {$wpdb->posts} ";
$sql .= " LEFT JOIN {$wpdb->postmeta} as price_meta ON {$wpdb->posts}.ID = price_meta.post_id " . $tax_query_sql['join'] . $meta_query_sql['join'];
$sql .= " WHERE {$wpdb->posts}.post_type = 'product'
AND {$wpdb->posts}.post_status = 'publish'
AND price_meta.meta_key IN ('" . implode("','", array_map('esc_sql', apply_filters('woocommerce_price_filter_meta_keys', array($price_meta_key)))) . "')
AND price_meta.meta_value > '' ";
$sql .= $tax_query_sql['where'] . $meta_query_sql['where'];
$sql = apply_filters('woof_get_filtered_price_query', $sql);
// Caching mechanism
if (isset(woof()->settings['price_transient']) AND woof()->settings['price_transient']) {
$data_key = md5($sql . 'woof');
$data = get_transient('woof_min_max_prices');
if (!is_array($data)) {
$data = array();
}
if (isset($data[$data_key])) {
$value = $data[$data_key];
return $value;
}
$prices = $wpdb->get_row($sql);
$data[$data_key] = $prices;
set_transient('woof_min_max_prices', $data, 1 * 24 * 3600); // 1 day
}
$prices = $wpdb->get_row($sql);
return $prices;}
- This reply was modified 3 days, 20 hours ago by aliceevra.
Hi, thank you , but when I want to added condition to use custom meta like “price-pro” based on type user connected, the range still false , the meta not taked.
- This reply was modified 1 week ago by aliceevra.
Hi , I added this customisation : same idea for the function get min :Price based on type user connected .
public static function get_max_price($additional_taxes = "") {
global $wpdb;
$meta_key = (is_user_logged_in() && get_user_meta(get_current_user_id(), 'statut_pro', true) === 'yes')
? '_prix_pro'
: '_price';
if (version_compare(WOOCOMMERCE_VERSION, '2.6', '>')) {
// Pour WooCommerce version supérieure à 2.6
$prices = self::get_filtered_price($additional_taxes);
$max = ceil($prices->max_price ?: 0);
} else {
// Pour WooCommerce version 2.6 ou inférieure
self::set_layered_nav_product_ids();
if (0 === sizeof(WC()->query->layered_nav_product_ids)) {
$sql_data = array(
array(
'val' => $wpdb->posts,
'type' => 'string',
),
array(
'val' => $wpdb->postmeta,
'type' => 'string',
),
array(
'val' => $meta_key, // Utiliser le bon meta_key selon le statut de l'utilisateur
'type' => 'string',
),
);
$query_txt = self::woof_prepare('
SELECT max(meta_value + 0)
FROM %1$s
LEFT JOIN %2$s ON %1$s.ID = %2$s.post_id
WHERE meta_key IN ("' . implode('","', apply_filters('woocommerce_price_filter_meta_keys', array($meta_key))) . '")
', $sql_data);
$max = ceil($wpdb->get_var($query_txt));
} else {
$sql_data = array(
array(
'val' => $wpdb->posts,
'type' => 'string',
),
array(
'val' => $wpdb->postmeta,
'type' => 'string',
),
);
$max = ceil($wpdb->get_var(
self::woof_prepare('
SELECT max(meta_value + 0)
FROM %1$s
LEFT JOIN %2$s ON %1$s.ID = %2$s.post_id
WHERE meta_key IN ("' . implode('","', apply_filters('woocommerce_price_filter_meta_keys', array($meta_key))) . '")
AND (
%1$s.ID IN (' . implode(',', array_map('absint', WC()->query->layered_nav_product_ids)) . ')
OR (
%1$s.post_parent IN (' . implode(',', array_map('absint', WC()->query->layered_nav_product_ids)) . ')
AND %1$s.post_parent != 0
)
)
', $sql_data
)));
}
}
// Added 20% for user not pro
if (!is_user_logged_in() || get_user_meta(get_current_user_id(), 'statut_pro', true) !== 'yes') {
$max = ceil($max * 1.2);
}
return $max;
}Hi , I have plugins like “Custom Post Type UI” .
Thanks in advance.
Hi, sometimes I am in the current category, I apply filters, and the results are correct, but the displayed categories change: they show categories from another section. How can I fix this? Thank you in advance. Here for example, I selected ‘PLL au mètre’ and the filters on the side have nothing to do with it anymore.
I filter in category A for example : the filtered products are correct, but on the side, we have other categories showing that we dont have relation with the current category filtered.
Thank you in advance.
- This reply was modified 1 month ago by aliceevra.
Hi, sometimes when I click on a filter category choice, the shop page reloads, but the filter symbol “+” remains open. The parents should be closed. How can I fix this, please?
- This reply was modified 1 month, 2 weeks ago by aliceevra.
Hi,
The disable Url SEO is on test .
I have other point , How can I optimize please the response time when users click on the filter? It is currently very slow.
Thank you!
- This reply was modified 1 month, 3 weeks ago by aliceevra.
Hi,thank you for your response but I have already set up this configuration. It seems to work correctly on one machine, but when someone else opens it on their machine, the bug reoccurs. We can test from page shop or navigate also in sub menu of “Tous nos produits” .The filter is not stable.
- This reply was modified 1 month, 4 weeks ago by aliceevra.
Hi , this is link : https://www.esp-enseignes.com/boutique/ : Sometimes the filter works correctly, and sometimes it breaks.
Forum: Fixing WordPress
In reply to: htaccess changed suddenlyHi , thank you , but I want to know the causes of problem .
Forum: Plugins
In reply to: [LiteSpeed Cache] How to remove generated file cssI try the two settings separately, but I got the same result
I found the source of problem: It is when I put “optimisation guest” in general active.
But with this option active I got a good score with lighthouse.Any idea please for this problem.
- This reply was modified 1 year, 10 months ago by aliceevra.
Forum: Plugins
In reply to: [LiteSpeed Cache] How to remove generated file cssHi, I try these instructions but I still got the same problem “Eliminate render-blocking resources”, “Reduce unused CSS”
Forum: Plugins
In reply to: [WooCommerce] Conflict between Orders guest and clientHi, for example when edit order number 222126 for client A .Then I CLICK
Profile -> display others orders
I found in profile client A
-the order 222126 (for this client)
-other order number 223568 (example ) for other account guest
Forum: Plugins
In reply to: [WooCommerce] Customize checkout page woocommerceHi @daniyalahmedk , that’s the request, thank you .but to contact expert e-commerce is paid
- This reply was modified 2 years, 4 months ago by aliceevra.