WooCommerce Hidden Categories? 4 Categories Shown “18 items” shown on Categories page

I am having a weird issue with WooCommerce… When viewing my product categories, It shows that I have 18 total, but it only shows 4 of them.

The other categories show up when I go to create a product, I can see and select those categories on that page. But I have no items in those categories, no attributes attached to them, no tags, etc. I just cannot seem to remove them, or understand what is keeping them around.

Any ideas would be helpful. I am using the LUSION theme, with the elementor builder.

4 Total Categories, with 18 Items shown

enter image description here

Update woocommerce thankyou page based on API request result

I create a custom woocommerce payment gateway plugin. First, I call an API, I take the formUrl from the response result then I redirect users to this payment form. At this step everything is Ok.

After the user enter his credit cards info and click validate the system redirect him to the default "order-received" page.

Before loading this page, I want to call another API to check the payment status, if the response body has the orderStatus== 1: I want to show the description in the response body (description = "Request processed successfully"), I reduce order stock, I update the status of order then I display the Order details. If the orderStatus == 2: I want to change the order status to ‘failed’ manually to show the default woocommerce-thankyou-order-failed message (”Unfortunately your order cannot be processed…") in the file thankyou.php or I just show a simple error payment message in this case.

In the payment class constractor I tried adding: add_action( ‘woocommerce_thankyou’, ‘thank_you_page’, 20, 1 ); but I dont know how to add my custom function or how to adapt this requirement.

My plugin looks like this one : https://github.com/YTTechiePress/custom-woocommerce-payment-gateway/blob/master/lesson-1/noob-payment-for-woocommerce.php

Upload file to Woocommerce Order

I’m trying to add File Upload for checkout process. Here is my code:

Add input after order notes

add_filter( 'woocommerce_after_order_notes', 'upload_file_checkout' ); function upload_file_checkout() {      ?>          <p class="form-row" id="image" data-priority="">         <label for="image" class="">Image (JPG, PNG, PDF)</label>         <span class="woocommerce-input-wrapper">         <input type='file' name='image' accept='image/*,.pdf' multiple='false'>         </span>     </p>         <?php } 

Next, update order meta

add_action( 'woocommerce_checkout_update_order_meta', 'checkout_file_update_order_meta' ); function checkout_file_update_order_meta($  order_id) {              if ( isset( $  _POST['image'] ) ) {                  require_once( ABSPATH . 'wp-admin/includes/image.php' );         require_once( ABSPATH . 'wp-admin/includes/file.php' );         require_once( ABSPATH . 'wp-admin/includes/media.php' );                  $  attachment_id = media_handle_upload( 'image', $  order_id );          update_post_meta( $  order_id, '_image', $  attachment_id );      }      } 

And show the result in admin page

add_action( 'woocommerce_admin_order_data_after_billing_address', 'show_new_checkout_field_order', 10, 1 );     function show_new_checkout_field_order( $  order ) {        $  order_id = $  order->get_id();    echo '<p><strong>Image:</strong> ' . get_post_meta( $  order_id, '_image', true ) . '</p>'; } 

But this is not work. How can I fix it?

This is how I see this meta in DB after place an order

enter image description here

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 attributes

I have two attributes Size and colour. the variation in Size are Small, Medium, Large and Extra Large and when we select the variation of Size attribute certain colours appear. The issue I am facing is if I select small size rest of variation of size attribute disappear which I don’t want to ? any ways to show all the variation of "Size" attribute even after selection?

Combining multiple numeric meta_key’s in an order_by query for a custom woocommerce sorting option [closed]

I would like to create a custom woocommerce product orderby sort option that combines the values of one custom numeric field

  • ‘sort_price’

with another numeric field (woocommerce regular price)

  • ‘_price’

And order the combined values in ASC order

edit: I see this forum is wordpress only, I will take this to the woocommerce plugin forum, apologies, I can’t seem to delete this.

My code so far achieves ordering by sort_price alone but I am unsure how to combine the two.

add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );  function custom_woocommerce_get_catalog_ordering_args( $  args ) {   $  orderby_value = isset( $  _GET['orderby'] ) ? wc_clean( $  _GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );     if ( 'random_list' == $  orderby_value ) {         $  args['orderby'] = 'meta_value_num';         $  args['order'] = 'ASC';         $  args['meta_key'] = 'sort_price';     }     return $  args; } add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' ); add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' ); function custom_woocommerce_catalog_orderby( $  sortby ) {     $  sortby['random_list'] = 'Price Low to High Custom';     return $  sortby; } 

there is an example in the wp codex which demonstrates using multiple meta keys but I am a little unsure of what the compare and value parts in the array are doing.

    'meta_query' => array(         'relation' => 'AND',         'state_clause' => array(             'key' => 'state',             'value' => 'Wisconsin',         ),         'city_clause' => array(             'key' => 'city',             'compare' => 'EXISTS',         ),      ),     'orderby' => array(          'city_clause' => 'ASC',         'state_clause' => 'DESC',     ),