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.

php – How To Show Featured Products First In WooCommerce

I am working on a Woocommerce theme that outputs first featured products and then products. The following args I am passing to the WP_Query. But it just returns only the Featured Product. If anybody could find a solution it will be helpful. Thanks.

            $_args = array(
                        'posts_per_page' => -1,
                        'post_type' => 'product',
                        'tax_query' => array(
                        'relation' => 'AND',
                            array(
                                'taxonomy' => 'product_cat',
                                'terms' => array( $t )
                            ),
                            array(
                                'taxonomy' => 'product_visibility',
                                'terms' => array( $t ),
                                'field'    => 'slug',
                                'terms'    => 'featured',
                                'operator' => 'IN'
                            )
                        )
                    );

woocommerce offtopic – Add class to h1 title on single product page using filter

I’m looking at my Single Product title template:

the_title( '<h1 class="product_title entry-title">', '</h1>' );

And I want to add a class (‘small’) to the title without modifying the template (to avoid problems with future updates).

I’d like to plop in a filter but don’t know how to do this. I suspect it’s something like this:

  add_filter( 'woocommerce_product_loop_title_classes', 'custom_woocommerce_product_title_classes' );
    
    function custom_woocommerce_product_title_classes( $class ) {
        return $class . ' small'; 
    }

Which seems to work for the shop page, but not the single product page.

WooCommerce sync product stock between products

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 offtopic – I would like to know if there is a plugin or how to do it, so that a site on that multisite network on a specific date

I have a network of sites (multisite), where I rent a site (plans), I would like to know if there is a plugin or how to do it, so that a site on that multisite network on a specific date.

For example:

1 customer rented a website for 2 months.

I want who on the last day of these 2 months, the site goes down with a message (expiration, canceled, contact us to activate).

Can someone help me?

plugins – Woocommerce Subscriptions weekly billing issue: Customer is charged twice in first week

Expected behaviour:
Trying to have customers pay when they signup THEN align with the renewal day of Wednesday, obviously excluding the current billing cycle which they have already paid for.

Actual behaviour:
1.Customer signs up on e.g. Tuesday and pays full price
2.THEN our weekly billing day (Wednesday) is reached and they are charged again for the subsequent delivery. This means they are being charged twice before they even receive the product!!.

WooCommerce REST API: Filter orders by advanced custom field

I am using WooCommerce and Advanced Custom Fields for the orders.
Is there a way to filters orders using the WooCommerce REST API by a custom field?

I’m guessing if there is no built in solution, perhaps some custom function can allow this.

Thank you.

php – How to change WooCommerce loop product title HTML output in single product page and archive page

I’m currently working on designing my custom WooCommerce theme and wondering how I could change the HTML output of loop_product_title in single product page and in archive pages.

I have less knowledge of functions but I made this content but it did not work. I just want the loop product title to have element and in archives pages to have .

if ( is_product() ){
function woocommerce_template_loop_product_title() {
echo '<h2 class="product-title">' . get_the_title() . '</h3>';
}
elseif ( is_shop() ){
function woocommerce_template_loop_product_title() {
echo '<span class="product-title">' . get_the_title() . '</span>';
}
}
}

Please someone help me out. I have tried the best of what I could.

Fully automated WooCommerce dropshipping | AliExpress

Hi, is there anyone who has ever had or created a fully automatic dropshipping eshop on woocommerce?
We researched the AliDropship plugin, but we would need full bulk automation of order processing.

We had a dropshipping eshop already and process 300-500 orders daily was terrible and unsustainable in the long run.

Is here somebody who is experienced in this?

Thank you!

Porto | Multipurpose & WooCommerce Theme | Nulled Scripts Download

+ Added: Porto Elementor recent portfolios widget
+ Added: Porto Elementor Circular Bar widget
+ Added: font size, font weight, letter spacing, padding and extra class input fields for Porto WPBakery Button element
+ Added: a margin bottom field for Porto Elementor Counter widget

– Fixed: Image lazyload issue in Owl Carousel with infinite loop
– Fixed: some order by fields were not working for products, blog and portfolio elements
– Fixed: Porto popup menu type wasn’t working on mobile for…

.