Disable woocommerce api authentication?

The woocommerce api takes oauth1.0 for HTTP requests and basic HTTP authentication for HTTPS requests. My query is simple. How to simply remove this authentication? I did some digging and found there is a class in woocommerce plugin with a constructor as

public function __construct() {

        // To disable authentication, hook into this filter at a later priority and return a valid WP_User
        add_filter( 'woocommerce_api_check_authentication', array( $this, 'authenticate' ), 0 );
    }

My job is to simply remove the authentication part. Here it is saying to hook this filter at a later priority. How to do so and how to return a valid WP_User?

Related posts

1 comment

  1. Create your own plugin and place the following code:

    function wc_authenticate_alter(){
        //return wp_get_current_user();
        if( 'GET' ==  WC()->api->server->method ){
            return new WP_User( 1 );
        } else {
            throw new Exception( __( 'You dont have permission', 'woocommerce' ), 401 );
        }
    }
    
    add_filter( 'woocommerce_api_check_authentication', 'wc_authenticate_alter', 1 );
    

    This will bypass woocommerce api authentication. Use it with your own risk.

    (You can add it in theme’s functions.php instead of own plugin. But not Tested.)

Comments are closed.