Woocommerce sale flash badge not showing in products page [closed]

the problem that I have is this. I am just helping someone with their woocommerce/wordpress website, I am not very experienced with it but they need some urgent help. Basically, they want to show a badge whenever a product is on sale. I just found the way to do it and it is working fine, but only in the single product page. In the page of a single product, in the related products it shows the badge in the discounted products. But in the general products page it does not show anything. This is the code I got for the single product pages:

function sales_badge( $  text, $  post, $  product ) {         return $  tagType = '<span class="onsale"><img style="max-width: 150px;" src="sale.jpg"></span>'; } add_filter('woocommerce_sale_flash', 'sales_badge', 99, 3 );  

For the theme we are using: Astra and Elementor. I have tried everything and in google but could not find anything related with this. FYI: we are not using any plugin for this and we do not plan to.

How to display products sort by Tags for Woocommerce

I have tried to display products by tags on shop page, i found this code and it workes perfectly

            $  args = array(                 'number'     => $  number,                 'orderby'    => 'title',                 'order'      => 'ASC',                 'hide_empty' => $  hide_empty,                 'include'    => $  ids             );             $  product_tags = get_terms( 'product_tag', $  args );             $  count = count($  product_tags);             if ( $  count > 0 ){                 foreach ( $  product_tags as $  product_tag ) {                     echo '<h4>' . $  product_tag->name . '</a></h4>';                     $  args = array(                         'posts_per_page' => -1,                         'tax_query' => array(                             'relation' => 'AND',                             array(                                 'taxonomy' => 'product_tag',                                 'field' => 'slug',                                 // 'terms' => 'white-wines'                                 'terms' => $  product_tag->slug,                                 'product_tag'=> "latest-product"                             )                         ),                         'post_type' => 'product',                         'orderby' => 'title,'                     );                     $  products = new WP_Query( $  args );                     woocommerce_product_loop_start();                     while ( $  products->have_posts() ) {                         $  products->the_post();                         do_action( 'woocommerce_shop_loop' );                         wc_get_template_part( 'content', 'product' );                         ?>                                                      <?php                     }                     woocommerce_product_loop_end();                 }             }          ?> 

But when I tried to filter resaults it wont apply filters, by the way i m using Annasta Filter Plugin


What kinds of Metallic Dragons were ever shown in D&D products? [closed]

Everyone knows the iconic metallic dragons that come in almost every single core monster book, Gold, Silver, Bronze, Copper, Brass. Let’s call those the “core five”

There were some others, like dunno Steel, Iron, Platinum, Electrum, Uranium(?), and what else…

What kinds of metallic dragons other than the “core five” were shown in D&D products?
What were their ecologies and demeanors?
In what worlds did they debut/existed?

WooCommerce – Get 10 Most Sold Products

I am trying to display the 10 most sold products on my website but I am not getting the right products. I am using the following code in order to get the relevant products:

$  query = new WP_Query(array(     'post_type'           => 'product',     'post_status'         => 'publish',     'posts_per_page'      => 10,     'meta_key'            => 'total_sales',     'orderby'             => 'meta_value_num',     'order'               => 'DESC', )); 

When I check in WooCommerce --> Reports --> Orders --> By Product, it displays 10 different products than the products I get using the above code.

So I did a little experiment and using the following code I am printing the amount a product is sold:

echo "total_sales: " . get_post_meta( $  product_id, 'total_sales', true ) . "<br>"; 

This code returns a different value then the value in WooCommerce --> Reports --> Orders --> By Product. For example, I have a product with an id 555565 and in WooCommerce --> Reports --> Orders --> By Product it says there are 47 sales of this product while get_post_meta( $ product_id, 'total_sales', true ) returns 3.

Also I am using the following code (which I found on StackOverflow) in order to print all the orders which includes product 555565 and it turns out the product is included in 43 orders:

function get_orders_ids_by_product_id( $  product_id, $  order_status = array( 'wc-completed' ) ){ global $  wpdb;  $  results = $  wpdb->get_col("     SELECT order_items.order_id     FROM {$  wpdb->prefix}woocommerce_order_items as order_items     LEFT JOIN {$  wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id     LEFT JOIN {$  wpdb->posts} AS posts ON order_items.order_id = posts.ID     WHERE posts.post_type = 'shop_order'     AND posts.post_status IN ( '" . implode( "','", $  order_status ) . "' )     AND order_items.order_item_type = 'line_item'     AND order_item_meta.meta_key = '_product_id'     AND order_item_meta.meta_value = '$  product_id' ");  return $  results; 


##To conclude##

I suspect something wrong with total_sales. If someone knows how to solve it, I will be grateful 🙂

If any more information is needed, please let me know and I will add it.

WooCommerce sync product stock between products [closed]

In my store, we sell belts and they have a Buckle which is counted in inventory.

The thing is that two belts can have one buckle.

The buckle is a separate Variation product I made.

I was wondering if it’s possible to sync the stock between the belts that use a specific variation of the Buckle.

For example:

If buckle No. 1 is out of stock, all belt using it are automatically out of stock.

Is this possible? I’ve tried chained products, but the problem here is that they still show up in the product catalog.

Woocommerce Filter Products by Price widget – filter by price in custom field

I have products with price per package in eshop. I also created custom field with product price per square meters. Products are sold only by package not by square meters, but on archive page I need filtering products by price per square meters. I unregistered WC_Widget_Price_Filter widget and registered modified version of that widget, which displays correct min and max prices in square meters in filter slider. I modified function price_filter_post_clauses to display correct products. Function is located in includes/class-wc-query.php.

public function price_filter_post_clauses( $  args, $  wp_query ) {     global $  wpdb;      // phpcs:ignore WordPress.Security.NonceVerification.Recommended     if ( ! $  wp_query->is_main_query() || ( ! isset( $  _GET['max_price'] ) && ! isset( $  _GET['min_price'] ) ) ) {         return $  args;     }      // phpcs:disable WordPress.Security.NonceVerification.Recommended     $  current_min_price = isset( $  _GET['min_price'] ) ? floatval( wp_unslash( $  _GET['min_price'] ) ) : 0;     $  current_max_price = isset( $  _GET['max_price'] ) ? floatval( wp_unslash( $  _GET['max_price'] ) ) : PHP_INT_MAX;     // phpcs:enable WordPress.Security.NonceVerification.Recommended      /**      * Adjust if the store taxes are not displayed how they are stored.      * Kicks in when prices excluding tax are displayed including tax.      */     if ( wc_tax_enabled() && 'incl' === get_option( 'woocommerce_tax_display_shop' ) && ! wc_prices_include_tax() ) {         $  tax_class = apply_filters( 'woocommerce_price_filter_widget_tax_class', '' ); // Uses standard tax class.         $  tax_rates = WC_Tax::get_rates( $  tax_class );          if ( $  tax_rates ) {             $  current_min_price -= WC_Tax::get_tax_total( WC_Tax::calc_inclusive_tax( $  current_min_price, $  tax_rates ) );             $  current_max_price -= WC_Tax::get_tax_total( WC_Tax::calc_inclusive_tax( $  current_max_price, $  tax_rates ) );         }     }      $  args['join']   = $  this->append_product_sorting_table_join( $  args['join'] );     $  args['where'] .= $  wpdb->prepare(         ' AND wc_product_meta_lookup.min_price >= %f AND wc_product_meta_lookup.max_price <= %f ',         $  current_min_price,         $  current_max_price     );     return $  args; } 

I modified sql in $ args[‘join’] and $ args[‘where’]. Is it possible to modify this function without modifying it directly?

How to stop WooCommerce from removing link functionality in uploaded PDF products

my site uses WooCommerce to sell downloadable PDFs which should have clickable links, but when these PDFs are downloaded after purchase, the links are no longer clickable. I’ve searched everywhere I can think to try to find a resolution to the problem. Has anyone encountered this before?

I’ve tried downloading with multiple browsers and opening the files in Acrobat and Preview, to no avail, so I think it looks like the links are being removed on upload to the site. I use an image optimiser (Smush) to process images on upload to the site, but this doesn’t affect PDFs.

I’m a little perplexed, any insight would be much appreciated.