function wc1c_delete_woocommerce_attribute($attribute_id) { global $wpdb; $attribute = wc1c_woocommerce_attribute_by_id($attribute_id); if (!$attribute) { return false; } delete_option("{$attribute['taxonomy']}_children"); $terms = get_terms($attribute['taxonomy'], "hide_empty=0"); foreach ($terms as $term) { wp_delete_term($term->term_id, $attribute['taxonomy']); } $wpdb->delete("{$wpdb->prefix}woocommerce_attribute_taxonomies", compact('attribute_id')); if (function_exists('wc1c_check_wpdb_error')) { wc1c_check_wpdb_error(); } }
function wc1c_clean_woocommerce_attributes($is_full) { global $wpdb; if (!$is_full || WC1C_PREVENT_CLEAN) { return; } $timestamps = get_option('wc1c_timestamp_attributes', array()); if (!$timestamps) { return; } $guids = get_option('wc1c_guid_attributes', array()); $attribute_ids = array(); foreach ($timestamps as $guid => $timestamp) { if ($timestamp != WC1C_TIMESTAMP) { $attribute_ids[] = $guids[$guid]; } } $attribute_ids = apply_filters('wc1c_clean_attributes', $attribute_ids); if (!$attribute_ids) { return; } foreach ($attribute_ids as $attribute_id) { $attribute = wc1c_woocommerce_attribute_by_id($attribute_id); if (!$attribute) { continue; } wc1c_delete_woocommerce_attribute($attribute_id); unset($guids[$guid]); unset($timestamps[$guid]); $is_deleted = true; } if (!empty($is_deleted)) { $orders = get_option('wc1c_order_attributes', array()); $order_index = array_search($attribute_id, $orders); if ($order_index !== false) { unset($orders[$order_index]); update_option('wc1c_order_attributes', $orders); } update_option('wc1c_guid_attributes', $guids); update_option('wc1c_timestamp_attributes', $timestamps); } }