From 755fc75ae97824002d141282987bff88406266a7 Mon Sep 17 00:00:00 2001 From: Almira Krdzic Date: Wed, 17 Oct 2018 11:31:09 +0200 Subject: [PATCH] Filter linked organizations as customer --- .../admin/class-wiaas-admin-organization.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-organization.php b/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-organization.php index f50c13f..708083f 100644 --- a/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-organization.php +++ b/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-organization.php @@ -18,10 +18,13 @@ class Wiaas_Admin_Organization { 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); + add_action('acf/save_post', array(__CLASS__, 'maybe_save_related_customers'), 11); // load related customers for organization form add_filter('acf/load_value/name=_wiaas_organization_customers', array(__CLASS__, 'load_related_customer_organizations'), 10, 3); + + // retrieve only customer organizations as options to link to commercial lead + add_filter('acf/fields/taxonomy/query/name=_wiaas_organization_customers', array(__CLASS__, 'filter_customer_organizations')); } public static function hide_woocommerce_customer_fields() { @@ -32,6 +35,22 @@ class Wiaas_Admin_Organization { return array(); } + /** + * Retrieve only customer organization as options to link customers to commercial lead + * + * @param $args + * + * @return array + */ + public static function filter_customer_organizations($args) { + + $args['meta_key'] = '_wiaas_organization_roles'; + $args['meta_value'] = 'customer'; + $args['meta_compare'] = 'LIKE'; + + return $args; + } + /** * 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