Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 347
user3423364 Avatar asked Nov 29 '25 03:11

user3423364


1 Answers

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.)

like image 173
Karthik Avatar answered Dec 01 '25 17:12

Karthik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!