Remove shop on org delete

This commit is contained in:
Almira Krdzic
2018-10-19 20:00:40 +02:00
parent a5a795af93
commit 5d8e759e80
3 changed files with 25 additions and 1 deletions

View File

@@ -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);

View File

@@ -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);
}
/**

View File

@@ -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 )
);
}
}