delete( $wpdb->postmeta, [ 'meta_key' => '_sdfw_amount' ] ); // ── Remove order-level meta added in later phases ─────────────────── // Order meta is written via WC_Order methods everywhere else in the // plugin, but uninstall.php runs in a stripped-down context — WordPress // core (and even WooCommerce itself) isn't guaranteed to be fully // bootstrapped, so a raw bulk DELETE against whichever table(s) are // actually in play is the standard, WordPress-core-approved uninstall // pattern, same as the postmeta cleanup above. $sdfw_order_meta_keys = [ '_sdfw_advance_amount', '_sdfw_cod_due', '_sdfw_advance_source_product_id', '_sdfw_processing_fee', '_sdfw_txn_id', ]; // Legacy (post-based) order storage keeps order meta in wp_postmeta, // same table as product meta above. foreach ( $sdfw_order_meta_keys as $sdfw_order_meta_key ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- one-time uninstall cleanup, not a query that runs on regular page loads, so there's no ongoing performance concern to index around. $wpdb->delete( $wpdb->postmeta, [ 'meta_key' => $sdfw_order_meta_key ] ); } // HPOS (High-Performance Order Storage) keeps order meta in a separate // wp_wc_orders_meta table instead of wp_postmeta. Guarded with // class_exists()/method_exists() — same defensive pattern the rest of // the plugin uses (see SDFW_Order::get_order_screen_id()) — since // WooCommerce's own classes aren't guaranteed to be loaded in the // uninstall.php context. if ( class_exists( \Automattic\WooCommerce\Utilities\OrderUtil::class ) && method_exists( \Automattic\WooCommerce\Utilities\OrderUtil::class, 'custom_orders_table_usage_is_enabled' ) && \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled() ) { $sdfw_orders_meta_table = $wpdb->prefix . 'wc_orders_meta'; // Confirm the table actually exists before querying it — HPOS being // "enabled" as a feature flag doesn't strictly guarantee the table // was created on every possible install/migration state. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange $sdfw_orders_meta_table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $sdfw_orders_meta_table ) ); if ( $sdfw_orders_meta_table_exists ) { foreach ( $sdfw_order_meta_keys as $sdfw_order_meta_key ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- one-time uninstall cleanup, not a query that runs on regular page loads, so there's no ongoing performance concern to index around. $wpdb->delete( $sdfw_orders_meta_table, [ 'meta_key' => $sdfw_order_meta_key ] ); } } } unset( $sdfw_order_meta_keys, $sdfw_order_meta_key, $sdfw_orders_meta_table, $sdfw_orders_meta_table_exists );