Add supplyer for organisation only if it has supplier role
This commit is contained in:
@@ -7,6 +7,7 @@ class Wiaas_Product_Supplier {
|
||||
|
||||
add_action('init', array(__CLASS__, 'register_supplier_taxonomy'));
|
||||
add_action('created_' . 'wiaas-user-organization', array(__CLASS__, 'on_organization_added'));
|
||||
add_action('edit_' . 'wiaas-user-organization', array(__CLASS__, 'on_organization_added'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,10 +50,11 @@ class Wiaas_Product_Supplier {
|
||||
*/
|
||||
public static function on_organization_added($organization_id) {
|
||||
$organization = get_term_by('id', $organization_id, 'wiaas-user-organization');
|
||||
$roles = wiaas_get_organization_roles($organization_id);
|
||||
|
||||
$supplier = term_exists($organization->slug, 'supplier');
|
||||
|
||||
if (! $supplier) {
|
||||
if (! $supplier && in_array('supplier', $roles) ) {
|
||||
$supplier = wp_insert_term($organization->name, 'supplier', array(
|
||||
'slug' => $organization->slug
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user