Hello, question!
If I have a custom field Search Weight “pondere_cautare”, where can I put this code, so that my product with search weight appears first in the category?
this is the code:
<?php
// …
do_action( ‘woodmart_woocommerce_main_loop’ ); // Before this line
// Custom sorting arguments
$args = array(
‘post_type’ => ‘product’,
‘posts_per_page’ => -1, // Show all products in the current category
‘orderby’ => ‘meta_value_num’, // Sort by numeric value of the meta field
‘meta_key’ => ‘pondere_cautare’, // Name of the custom field
‘order’ => ‘DESC’, // Descending order
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
// Display product information here
the_title(); // Product title
the_excerpt(); // Product excerpt
// …
}
wp_reset_postdata();
} else {
echo ‘No products found in this category.’;
}
// …
?>
Thank you
Attachments:
You must be
logged in to view attached files.