Support » Plugin: Advanced Order Export For WooCommerce » Only Export If Order Only Contains Category

  • Resolved prodograw

    (@prodograw)


    how can i export only if certain product category is in the order.

    at present my settings work but
    e.g
    Only Export “cat1”
    order will still export if cat1,cat2,cat3 is in order

    obviously i understand that because cat1 is in the order it will export i would like it not to export if any other category in order

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

    (@algolplus)

    please, open “Filter by product” and unmark “Export all products from the order”

    hi,

    that only removes the items from the order export thats not wanted

    i only want the order to export “ONLY” if cat1 is in the order

    if cat1 is in the order plus any other categorys dont export at all

    Thanks again and appreciate your time

    Plugin Author algol.plus

    (@algolplus)

    Sorry, no way via UI.
    tweak this code and add to “Misc Settings”.

    add_filter("woe_order_export_started", function($order_id){
      $has_only_cat1 = false;
      $order = new WC_Order($order_id);
      foreach ( $order->get_items('line_item') as $item_id=>$item ) {
         $categories = get_the_terms($item['product_id'], "product_cat");
         // you have to analyse $categories and set $has_only_cat1
         // code it yourself
      }
      return $has_only_cat1? false: $order_id;
    });
    • This reply was modified 2 months, 2 weeks ago by algol.plus.

    works a treat thank you !

    Plugin Author algol.plus

    (@algolplus)

    Could you paste final/updated PHP code to this ticket ?

    Hi sorry i haven’t got back to you

    below is what i used to achieve what i wanted hope it helps others:

    add_filter("woe_order_export_started", function($order_id){
      $has_only_cat1 = false;
      $order = new WC_Order($order_id);
      
      // categories you want to pass as true and break the export on the ORDER
      $pass_cat_as_false = array("sample","bundle","raw");
      
      foreach ( $order->get_items('line_item') as $item_id=>$item ) {
        $cats = get_the_terms($item['product_id'], "product_cat");
        $list_Cats=array();
        if ( is_array( $cats ) ) {
        	foreach ( $cats as $term ) {
    	}    
            $product_cat_slug = $term->name;
            
    	    if (in_array($product_cat_slug, $list_Cats)) {
    	        continue;
    	    }
            $list_Cats[] = $product_cat_slug;
            
    
        }
         if (strpos(strtolower ($product_cat_slug),$pass_cat_as_true) !== false) {
             $has_only_cat1 = true;
             break;
         }
      }
      return $has_only_cat1? false: $order_id;
    });
    
    • This reply was modified 2 months, 1 week ago by prodograw.
    Plugin Author algol.plus

    (@algolplus)

    thank you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.