• Resolved hairyashell

    (@hairyashell)


    Is it possible to add a custom column that takes the total weight of each order and multiplies it by a stated number?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter hairyashell

    (@hairyashell)

    I tried adding the following code to have a field (total_sauce) calculated from the total weight of each order:

    add_filter(‘woe_get_order_product_value_total_sauce’, function ($value, $order, $item, $product,$item_meta) {

    $value = $item[‘total_weight’]/8;
    return $value;
    }, 10, 5);

    I already added the field and it’s showing up but the calculated value is not showing up.

    Plugin Author algol.plus

    (@algolplus)

    we have to calculate total weight. So anyone who needs similar field

    Please, follow to https://algolplus.freshdesk.com/support/solutions/articles/25000016635-add-calculated-field-for-order-
    use meta key “total_sauce” and this PHP code.

    add_filter('woe_get_order_value_total_sauce', function ($value, $order, $fieldname) {
    	$total_weight = 0;
    	foreach( $order->get_items() as $item_id => $product_item ){
    		$quantity = $product_item->get_quantity(); // get quantity
    		$product = $product_item->get_product(); // get the WC_Product object
    		$product_weight = $product ? $product->get_weight() : 0; // get the product weight
    		// Add the line item weight to the total weight calculation
    		$total_weight += floatval( $product_weight) * $quantity ;
    	}
    	return $total_weight/8;
    }, 10, 3);
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘A multiple of total weight per order’ is closed to new replies.