- This topic has 8 replies, 3 voices, and was last updated 3 years, 1 month ago by Elvin.
-
AuthorPosts
-
February 24, 2021 at 1:25 pm #1671222chris
Hi some of my hook elements have stopped working, not sure why but all the ones i had to display on the woo product archive page have stopped displaying on there.
Is there any reason for this to have happened?
February 24, 2021 at 1:46 pm #1671241YingStaffCustomer SupportHi Chris,
Could you check if there’s any conflicts in terms of location settings?
If not, try disable all plugins except GP Premium and woocommerce to test.
If you can’t find any issues, could you please provide login info using the private info field.
Thanks!
February 24, 2021 at 1:53 pm #1671244chrisLiterally nothing has changed other than me adding products to the site which wouldn’t of interfered.
February 24, 2021 at 2:02 pm #1671253YingStaffCustomer SupportThe login you provided doesn’t work for me.
But could you try what I said in my previous reply first? Thanks!
February 24, 2021 at 2:55 pm #1671313chrisThis snippet is causing the issue, but im not sure how?
/**
* Sorting out of stock WooCommerce products – Order product collections by stock status, in-stock products first.
*/
class iWC_Orderby_Stock_Status
{
public function __construct()
{
// Check if WooCommerce is active
if (in_array(‘woocommerce/woocommerce.php’, apply_filters(‘active_plugins’, get_option(‘active_plugins’)))) {
add_filter(‘posts_clauses’, array($this, ‘order_by_stock_status’), 2000);
}
}
public function order_by_stock_status($posts_clauses)
{
global $wpdb;
// only change query on WooCommerce loops
if (is_woocommerce() && (is_shop() || is_product_category() || is_product_tag())) {
$posts_clauses[‘join’] .= ” INNER JOIN $wpdb->postmeta istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) “;
$posts_clauses[‘orderby’] = ” istockstatus.meta_value ASC, ” . $posts_clauses[‘orderby’];
$posts_clauses[‘where’] = ” AND istockstatus.meta_key = ‘_stock_status’ AND istockstatus.meta_value <> ” ” . $posts_clauses[‘where’];
}
return $posts_clauses;
}
}
new iWC_Orderby_Stock_Status;
/**
* END – Order product collections by stock status, instock products first.
*/February 24, 2021 at 4:37 pm #1671393ElvinStaffCustomer SupportHi there,
I believe you’ve taken it from this? https://stackoverflow.com/a/40629857
Can you try this one and not change anything and see if it works? Let us know.
February 25, 2021 at 4:06 pm #1672989chrisThat doesnt seem to work fully. When clicking a category the out of stock products dont display after the in stock products, which is what the whole piece of code was for i believe.
As i say, i tried the code you supplied but it doesnt do what the first piece did, thanks for the reply
February 25, 2021 at 5:10 pm #1673023chrisThe snipper im using is this one: https://wpdoityourself.com/sorting-out-of-stock-woocommerce-products-wordpress/
im not sure why it effects the elements dissapearing from the shop archive page.
February 25, 2021 at 8:57 pm #1673126ElvinStaffCustomer SupportI’m not exactly sure how these snippets fare with the most recent updates of WooCommerce. Perhaps that’s actually why it stopped working.
But IMO I think what better to do is to filter the product query.
Something like this – https://stackoverflow.com/a/62353255
Note: This isn’t actually a GP question but rather, a WooCommerce plugin question related to its product queries. It may be best to ask WooCommerce’s support if they have any best practice/recommendation on how to do this.
-
AuthorPosts
- You must be logged in to reply to this topic.