How can I set a filter for already purchased items?
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page pleaseIf you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.
Quote from SZGY on August 4, 2023, 12:31Hello, I would like to make a filter for make the already purchased items hide/show from the customers, how can I do that?
Thank you!
Hello, I would like to make a filter for make the already purchased items hide/show from the customers, how can I do that?
Thank you!
Quote from admin on August 7, 2023, 13:03Hello
This need custom code in the file functions.php of the current wp theme to exclude such products from the filtering, here is an example, but you need also code how to get products IDs already purchased by the customer:
- you need hook 'pre_get_posts' https://developer.wordpress.org/reference/hooks/pre_get_posts/
- place next code into file functions.php of the current wp theme
add_action('pre_get_posts', function ($query) { if (is_object($query) AND isset($query->query['post_type'])) { if ($query->query['post_type'] === 'product' /* AND is_page(1867) */) { if (isset($query->query['wc_query']) AND 'product_query' == $query->query['wc_query']) { return $query; } global $WOOF; if (is_object($WOOF) AND !empty(woof()->get_request_data())) { woof()->woof_products_ids_prediction(true); $query->query_vars['post__not_in'] = [22,74,58]; } } } return $query; });- [22,74,58] - this is IDs of the products bought by the current user, and you should define it, I found: https://njengah.com/woocommerce-display-products-purchased-user/ - you need to find how to get all products bought by current woocommerce user
Hello
This need custom code in the file functions.php of the current wp theme to exclude such products from the filtering, here is an example, but you need also code how to get products IDs already purchased by the customer:
- you need hook 'pre_get_posts' https://developer.wordpress.org/reference/hooks/pre_get_posts/
- place next code into file functions.php of the current wp theme
add_action('pre_get_posts', function ($query) { if (is_object($query) AND isset($query->query['post_type'])) { if ($query->query['post_type'] === 'product' /* AND is_page(1867) */) { if (isset($query->query['wc_query']) AND 'product_query' == $query->query['wc_query']) { return $query; } global $WOOF; if (is_object($WOOF) AND !empty(woof()->get_request_data())) { woof()->woof_products_ids_prediction(true); $query->query_vars['post__not_in'] = [22,74,58]; } } } return $query; }); - [22,74,58] - this is IDs of the products bought by the current user, and you should define it, I found: https://njengah.com/woocommerce-display-products-purchased-user/ - you need to find how to get all products bought by current woocommerce user
Quote from SZGY on August 7, 2023, 13:31hello, this is make a filter (Show/Hide)?
I found many code what hides, but I want it "toggle"
only i have to copy the code, or do something else?
Thank you!
hello, this is make a filter (Show/Hide)?
I found many code what hides, but I want it"toggle"
only i have to copy the code, or do something else?
Thank you!
Quote from Alex Dovlatov on August 8, 2023, 11:47Hello
What is here suggested is just filter part and idea how to create such toggle button, but this is not a fully implemented solution
I only provided part related to the filter, you need to find code which get products IDs bought by the customer
If you want to make toggle for this you can create button and if user click on it in cookies is going record, and page reloading. To make script listening this here is another version of the script:
add_action('pre_get_posts', function ($query) { if (is_object($query) AND isset($query->query['post_type']) AND intval($_COOKIE['can_cut_bought'])) { if ($query->query['post_type'] === 'product' /* AND is_page(1867) */) { if (isset($query->query['wc_query']) AND 'product_query' == $query->query['wc_query']) { return $query; } global $WOOF; if (is_object($WOOF) AND !empty(woof()->get_request_data())) { woof()->woof_products_ids_prediction(true); $query->query_vars['post__not_in'] = get_products_bought(); } } } return $query; });
get_products_bought(); - you need to get such function somewhere
Hello
What is here suggested is just filter part and idea how to create such toggle button, but this is not a fully implemented solution
I only provided part related to the filter, you need to find code which get products IDs bought by the customer
If you want to make toggle for this you can create button and if user click on it in cookies is going record, and page reloading. To make script listening this here is another version of the script:
add_action('pre_get_posts', function ($query) {
if (is_object($query) AND isset($query->query['post_type']) AND intval($_COOKIE['can_cut_bought'])) {
if ($query->query['post_type'] === 'product' /* AND is_page(1867) */) {
if (isset($query->query['wc_query']) AND 'product_query' == $query->query['wc_query']) {
return $query;
}
global $WOOF;
if (is_object($WOOF) AND !empty(woof()->get_request_data())) {
woof()->woof_products_ids_prediction(true);
$query->query_vars['post__not_in'] = get_products_bought();
}
}
}
return $query;
});
get_products_bought(); - you need to get such function somewhere