Divi custom headers Code Snippets Error
Closed this issue · 2 comments
Hello.
Divi Theme in WordPress gives you the possibility to custom the header of every page in your site. I have two headers, one for the Homepage and another one for the Store Page and for the product page.
I discovered that when Code Snippets plugin is on, the custom header in the Store page is replaced with the main header (homepage), but the Product pages do have the header they are supposed to. If I turn off the plugin, the problem disappear.
None of my code snippets has to do with the header style (css).
This issue has at least 7 months.
Homepage: medicalgear.com
Store Page: medicalgear.com/tienda
Product Page example: https://www.medicalgear.com/producto/bascula-pediatrica-20-kg
I hope someone can help me.
Thank you,
Pepe
I found the snippet that was causing the error. It was intended to order the products in the store according to the stock. Now I just need to figure out how to correct it.
Any idea? Here ir my code. Thank you.
add_filter('posts_clauses', 'sin_stock_al_final_woocommerce');
function sin_stock_al_final_woocommerce($posts_clauses) {
global $wpdb;
// Solo cambiar la consulta en los bucles de WooCommerce
if (is_woocommerce() && (is_shop() || is_product_category() || is_product_tag() || is_product_taxonomy())) {
$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;
}
I found a code that solve this problem:
function _nok_order_by_stock_status( $posts_clauses, $query ) {
// only change query on WooCommerce loops
if ( $query->is_main_query() && ( is_product_category() || is_product_tag() || is_product_taxonomy() || is_shop() ) ) {
global $wpdb;
$posts_clauses['join'] .=
" LEFT JOIN (
SELECT post_id, meta_id, meta_value FROM $wpdb->postmeta
WHERE meta_key = '_stock_status' AND meta_value <> ''
) istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) ";
$posts_clauses['orderby'] =
" CASE istockstatus.meta_value WHEN
'outofstock' THEN 1
ELSE 0
END ASC, " . $posts_clauses['orderby'];
}
return $posts_clauses;
}
add_filter( 'posts_clauses', '_nok_order_by_stock_status', 2000, 2 );