feat: WooCommerce Business Central integration plugin
Native PHP plugin (no Composer) that syncs: - Product stock and pricing from BC to WooCommerce (scheduled cron) - Orders from WooCommerce to BC (on payment received) - Auto-creates customers in BC from WooCommerce billing data Product matching: WooCommerce SKU → BC Item Number, fallback to GTIN (EAN). OAuth2 client credentials auth with encrypted secret storage. Admin settings page with connection test, manual sync, and log viewer. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
75
woo-business-central/uninstall.php
Normal file
75
woo-business-central/uninstall.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Uninstall WooCommerce Business Central Integration
|
||||
*
|
||||
* @package WooBusinessCentral
|
||||
*/
|
||||
|
||||
// Exit if uninstall not called from WordPress
|
||||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check if user wants to delete data (optional, could be a setting)
|
||||
$delete_data = get_option( 'wbc_delete_data_on_uninstall', 'no' );
|
||||
|
||||
// Always delete these options
|
||||
$options_to_delete = array(
|
||||
'wbc_tenant_id',
|
||||
'wbc_client_id',
|
||||
'wbc_client_secret',
|
||||
'wbc_environment',
|
||||
'wbc_company_id',
|
||||
'wbc_sync_frequency',
|
||||
'wbc_enable_stock_sync',
|
||||
'wbc_enable_price_sync',
|
||||
'wbc_enable_order_sync',
|
||||
'wbc_default_payment_terms_id',
|
||||
'wbc_default_shipment_method_id',
|
||||
'wbc_shipping_item_number',
|
||||
'wbc_last_sync_time',
|
||||
'wbc_encryption_key',
|
||||
'wbc_delete_data_on_uninstall',
|
||||
);
|
||||
|
||||
foreach ( $options_to_delete as $option ) {
|
||||
delete_option( $option );
|
||||
}
|
||||
|
||||
// Delete transients
|
||||
delete_transient( 'wbc_access_token' );
|
||||
|
||||
// Clear scheduled events
|
||||
$sync_timestamp = wp_next_scheduled( 'wbc_product_sync_event' );
|
||||
if ( $sync_timestamp ) {
|
||||
wp_unschedule_event( $sync_timestamp, 'wbc_product_sync_event' );
|
||||
}
|
||||
|
||||
$cleanup_timestamp = wp_next_scheduled( 'wbc_log_cleanup_event' );
|
||||
if ( $cleanup_timestamp ) {
|
||||
wp_unschedule_event( $cleanup_timestamp, 'wbc_log_cleanup_event' );
|
||||
}
|
||||
|
||||
// Drop logs table
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . 'wbc_logs';
|
||||
$wpdb->query( "DROP TABLE IF EXISTS $table_name" );
|
||||
|
||||
// Delete user meta (BC customer IDs)
|
||||
$wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key IN ('_wbc_bc_customer_id', '_wbc_bc_customer_number')" );
|
||||
|
||||
// Delete post meta (BC item info, order sync info)
|
||||
$wpdb->query( "DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE '_wbc_%'" );
|
||||
|
||||
// Delete order meta for HPOS (if using custom order tables)
|
||||
if ( class_exists( 'Automattic\WooCommerce\Utilities\OrderUtil' ) ) {
|
||||
if ( Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled() ) {
|
||||
$orders_table = $wpdb->prefix . 'wc_orders_meta';
|
||||
if ( $wpdb->get_var( "SHOW TABLES LIKE '$orders_table'" ) === $orders_table ) {
|
||||
$wpdb->query( "DELETE FROM $orders_table WHERE meta_key LIKE '_wbc_%'" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clear any cached data
|
||||
wp_cache_flush();
|
||||
Reference in New Issue
Block a user