• Resolved philipewert

    (@philipewert)


    Hey!

    Is there a function or PHP-Snippet to filter orders by weight?
    For example only exports orders above 0.4kg?
    I tried to solve it by myself but have no clue where to find the variable-names…

    Greetings!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author algol.plus

    (@algolplus)

    hi

    Woocommerce doesn’t record total weight for the order,
    so we have to calculate it on-fly.

    Could you paste following code to “Misc Settings”?
    thanks, Alex

    add_filter("woe_order_export_started", function($order_id ) {
    	$order = new WC_Order($order_id);
    
    	$total_weight = 0;
    	foreach( $order->get_items() as $item_id => $product_item ){
    		$product = $product_item->get_product(); 
    		if( $product )
    			$total_weight += floatval( $product->get_weight() * $product_item->get_quantity() );
    	}
    	return ($total_weight>0.4)  ? $order_id : false;
    });
    Thread Starter philipewert

    (@philipewert)

    Works perfectly fine!
    Thank you very much 🙂

    Plugin Author algol.plus

    (@algolplus)

    you’re welcome.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Filter orders by weight’ is closed to new replies.