reseller to customer
This commit is contained in:
@@ -14,8 +14,14 @@ class Wiaas_Admin_Organization {
|
||||
|
||||
add_filter('get_role_list', array(__CLASS__, 'get_role_list_for_user'), 10, 2);
|
||||
|
||||
|
||||
// hide woocommerce meta fields form customer user profile
|
||||
add_filter('woocommerce_customer_meta_fields', array(__CLASS__, 'hide_woocommerce_customer_fields'));
|
||||
|
||||
// save related customers when organization form data has been saved by acf
|
||||
add_action('acf/save_post', array(__CLASS__, 'maybe_save_related_customers'), 1);
|
||||
|
||||
// load related customers for organization form
|
||||
add_filter('acf/load_value/name=_wiaas_organization_customers', array(__CLASS__, 'load_related_customer_organizations'), 10, 3);
|
||||
}
|
||||
|
||||
public static function hide_woocommerce_customer_fields() {
|
||||
@@ -26,6 +32,49 @@ class Wiaas_Admin_Organization {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves related customers if organization new/edit form has been submited
|
||||
* Customer ids are collected from posted data of linked customers acf field and saved
|
||||
*
|
||||
* @param string $id in format `term_{$organization_id}`
|
||||
*/
|
||||
public static function maybe_save_related_customers($id) {
|
||||
if ($_POST['taxonomy'] === Wiaas_User_Organization::TAXONOMY_NAME && ! empty($_POST['acf'])) {
|
||||
|
||||
$field = get_field_object('_wiaas_organization_customers', $id);
|
||||
//get organization id
|
||||
$id = absint(str_replace('term_', '', $id));
|
||||
|
||||
$customer_organization_ids = $_POST['acf'][$field['key']];
|
||||
|
||||
$customer_organization_ids = is_array($customer_organization_ids) ?
|
||||
wp_parse_id_list($customer_organization_ids) :
|
||||
array();
|
||||
|
||||
Wiaas_Shop::set_shop_customers($id, $customer_organization_ids);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads related customers for linked customers acf field on organization edit form
|
||||
*
|
||||
* @param array $value
|
||||
* @param string $id in format `term_{$organization_id}`
|
||||
* @param array $field acf field details
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function load_related_customer_organizations($value, $id, $field) {
|
||||
//get organization id
|
||||
$id = absint(str_replace('term_', '', $id));
|
||||
|
||||
$customers = wp_list_pluck(
|
||||
Wiaas_Shop_Data_Store::get_shop_customers($id),
|
||||
'customer_id');
|
||||
|
||||
return $customers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render user organization roles as available user roles on user list
|
||||
* @param $role_list
|
||||
|
||||
Reference in New Issue
Block a user