1
votes

I am creating a new custom plugin in WooCommerce. I have to upload a file using ajax from front end so I added following code in my payment gateway class. I want to create a new ajax endpoint in class.

I added following line in constructor.

add_action( 'wc_ajax_wc_upload_payment_receipt', array( $this, 'wc_ajax_upload_payment_receipt'));

And create following function in class

public function wc_ajax_upload_payment_receipt(){
 echo "hi";
 print_r($_REQUEST);
}

Now when I call my ajax request using WC_AJAX::get_endpoint( 'wc_ajax_upload_payment_receipt' ) it is returning nothing.

Why is it not going inside my created function?

1
Your actual code, is not testable: "The question should be updated to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem.".LoicTheAztec

1 Answers

0
votes

Note that your action hook name should not have the same name than the function name…

Woocommerce Classes are case sensitive, so replace wrong WC_AJAX by WC_Ajax when using the method get_endpoint():

WC_Ajax::get_endpoint( $request );

Related documentation: Woocommerce WC_Ajax Class source code