From 5d8e759e80d38e5b2696bbe9782f44887b258f99 Mon Sep 17 00:00:00 2001 From: Almira Krdzic Date: Fri, 19 Oct 2018 20:00:40 +0200 Subject: [PATCH] Remove shop on org delete --- .../admin/class-wiaas-admin-organization.php | 2 +- .../app/plugins/wiaas/includes/class-wiaas-shop.php | 13 +++++++++++++ .../wiaas/includes/db/class-wiaas-shop-db.php | 11 +++++++++++ 3 files changed, 25 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 708083f..cb23fbd 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,7 +18,7 @@ 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'), 11); + // 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); diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-shop.php b/backend/app/plugins/wiaas/includes/class-wiaas-shop.php index 073ddb6..2310777 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-shop.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-shop.php @@ -22,6 +22,8 @@ class Wiaas_Shop { // create new shop if organization was assigned commercial lead role // or remove shop if commercial lead role was removed for organization add_action('wiaas_organization_roles_updated', array(__CLASS__, 'maybe_manage_shop_for_commercial_lead'), 10, 2); + + add_action('wiaas_organization_deleted', array(__CLASS__, 'maybe_remove_shop')); } public static function get_shop_customers($owner_id) { @@ -100,6 +102,15 @@ class Wiaas_Shop { self::_maybe_remove_shop($owner_id); } + /** + * Remove shop + * + * @param int $owner_id + */ + public static function maybe_remove_shop($owner_id) { + self::_maybe_remove_shop($owner_id); + } + /** * Register special prices taxonomy to enable search of packages by prices inside every shop */ @@ -197,6 +208,8 @@ class Wiaas_Shop { if ($attribute_id > 0) { wc_delete_attribute($attribute_id); } + + Wiaas_Shop_DB::remove_shop($owner_id); } /** diff --git a/backend/app/plugins/wiaas/includes/db/class-wiaas-shop-db.php b/backend/app/plugins/wiaas/includes/db/class-wiaas-shop-db.php index 9a41f73..1eda95e 100644 --- a/backend/app/plugins/wiaas/includes/db/class-wiaas-shop-db.php +++ b/backend/app/plugins/wiaas/includes/db/class-wiaas-shop-db.php @@ -154,4 +154,15 @@ class Wiaas_Shop_DB { return $shops; } + + public static function remove_shop($owner_id) { + global $wpdb; + + $wpdb->query( + $wpdb->prepare( + "DELETE FROM {$wpdb->prefix}wiaas_shop_customer_relationships + WHERE shop_owner_id = %d", + $owner_id ) + ); + } } \ No newline at end of file