Snippet code

Disable WordPress and WooCommerce user access

If you need to disable wordpress account this code give you the ability to disable account user by user id. To find the user id follow those step.

  • Go to Users → All Users
  • Hover your mouse over a username (do not click)
  • Look at the bottom of your browser (or right-click → Copy link)

You will see a link like: user-edit.php?user_id=17. ➡️ 17 is the user ID

add_filter( 'authenticate', function( $user, $username, $password ) {

    if ( is_wp_error( $user ) || ! $user instanceof WP_User ) {
        return $user;
    }

    $blocked_user_ids = [  ]; // ← place IDs number, number ex:[12,26,52]

    if ( in_array( (int) $user->ID, $blocked_user_ids, true ) ) {
        return new WP_Error(
            'account_disabled',
            'Your account is deactivated. Please contact the administrator.' // You can customize the message here
        );
    }

    return $user;

}, 30, 3 );

Enable WooCommerce duplicate order on all status

Enables customers to duplicate WooCommerce orders from the frontend for all order statuses. By default, this feature is only available for completed orders.

add_filter( 'woocommerce_valid_order_statuses_for_order_again', function( $statuses ) {
    return array(
        'completed',
        'processing',
        'on-hold',
    );
});