Give order access to suppliers , when order is created
This commit is contained in:
@@ -17,6 +17,7 @@ class Wiaas_Access_Management {
|
|||||||
add_action( 'save_post', array( __CLASS__, 'maybe_handle_product_access' ), 999, 2 );
|
add_action( 'save_post', array( __CLASS__, 'maybe_handle_product_access' ), 999, 2 );
|
||||||
|
|
||||||
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
|
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
|
||||||
|
add_action('woocommerce_payment_complete', array( __CLASS__, 'assign_order_to_suppliers'),20,1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,6 +77,27 @@ class Wiaas_Access_Management {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assignees order to supplier organizations extracted from ordered items when order payment is complete.
|
||||||
|
*
|
||||||
|
* @param int $order_id
|
||||||
|
*/
|
||||||
|
public static function assign_order_to_suppliers($order_id){
|
||||||
|
|
||||||
|
$order = wc_get_order($order_id);
|
||||||
|
$product_from_order = $order->get_items('line_item');
|
||||||
|
|
||||||
|
foreach ($product_from_order as $product) {
|
||||||
|
|
||||||
|
$supplier_terms = wp_get_object_terms($product->get_product_id(), 'supplier');
|
||||||
|
$supplier_organisation_slug = $supplier_terms[0]->slug;
|
||||||
|
$supplier_organisation_id = get_term_by('slug' ,$supplier_organisation_slug,'wiaas-user-organization')->term_id;
|
||||||
|
|
||||||
|
Wiaas_User_Organization::assign_post_to_organization($order_id, $supplier_organisation_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Wiaas_Access_Management::init();
|
Wiaas_Access_Management::init();
|
||||||
|
|||||||
Reference in New Issue
Block a user