Here is how a WooCommerce coupon code can be checked for validity. The code below allows us to check WooCommerce coupon against the database. This is done using the inbuilt WC_Coupon class provided by WooCommerce.
The coupon code is sent to the function coupon_check_via_ajax(). The above function is AJAX enabled by registering it with wordpress AJAX using wp_ajax_*actions for both logged in and public users.
More about WC_Coupon from the WooCommerce documentation can be found here
Feature photo by Nimit Kansagra