Archived topic
Elements stopped working
8 replies · Started by chris on February 24, 2021
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?
Hi 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!
Literally nothing has changed other than me adding products to the site which wouldn't of interfered.
The login you provided doesn't work for me.
But could you try what I said in my previous reply first? Thanks!
This 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.
*/
Hi 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.
That 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
The 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.
I'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.