Ecommerce Shopify WordPress Discussion

Wocommerce Attribute Quantity / Packs on Admin Order Details Page

I have an Woocommerce online store and I want to sell a product in packs of several units. In other words, it will be a variable product (but all variations will have the same SKU), with the attribute "Pack" in which the variations are, for example: "1 unit", "5 units" and "20 units". I need a code snippet with these requirements: 1 - When the customer orders a variation whose term is greater than "1", the stock must be reduced by that quantity. For example, if the customer orders the "20 units" variation, 20 units must be removed from stock. 2 - If the customer orders, for example, the "20 units" variation, on the Admin Order Details Page, the number 20 must appear in the "Quantity" column. In other words, 20 units of that SKU will be invoiced and not 1 pack of 20 units. (See the attached image: I have this code that I pasted into functions.php and fulfills the first requirement. // Modify order item quantity based on pack size add_filter( 'woocommerce_order_item_quantity', 'filter_order_item_quantity', 10, 3 ); function filter_order_item_quantity( $quantity, $order, $item ) { $product = $item->get_product(); $term_name = $product->get_attribute('pa_Pack'); $quantity_units = preg_replace('/[^0-9.]+/', '', $term_name); if( is_numeric ( $quantity_units ) && $quantity_units != 0 ) $quantity *= $quantity_units; return $quantity; } But i don't know how to make the second requirement work. Can someone help? I already tried this (for the second requirement), but didn't work: // Display individual quantity in admin order details for pack products add_filter( 'woocommerce_admin_order_item_values', 'display_individual_quantity_in_admin_order', 10, 3 ); function display_individual_quantity_in_admin_order( $order_item_data, $item, $order ) { $product = $item->get_product(); $term_name = $product->get_attribute('pa_Pack'); $quantity_units = preg_replace('/[^0-9.]+/', '', $term_name); if( is_numeric( $quantity_units ) && $quantity_units != 0 ) { $order_item_data['quantity'] = $quantity_units; } return $order_item_data; }
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.