终于成功了。
add_action(\'before_delete_post\', \'removeCheckDetail\', 10, 1 );
function removeCheckDetail( $order_id ) {
global $woocommerce;
global $wpdb;
$order = new WC_Order($order_id);
$order_items = $order->get_items();
// Loop through order line items
foreach( $order_items as $item_id => $item ) {
$url = $item->get_meta(\'Check Detail\');
parse_str( parse_url( $url, PHP_URL_QUERY), $array );
$key = strstr($array[\'ck_item\'], \'"\', true);
$wpdb->check_detail = "{$wpdb->prefix}check_detail";
$wpdb->delete($wpdb->check_detail, array(\'cart_item_key\' => $key));
}
}