'%%endpoint%%', ); } else { $query_args = array( 'wc-ajax' => $request, ); } $uri = explode( '?', esc_url_raw( $_SERVER['REQUEST_URI'] ), 2 ); $url = esc_url( $uri[0] ); } $query_args['wcf_checkout_id'] = $post->ID; $endpoint_url = add_query_arg( $query_args, $url ); } } return $endpoint_url; } /** * Apply coupon on submit of custom coupon form. */ public function apply_coupon() { $response = ''; if ( ! check_ajax_referer( 'wcf-apply-coupon', 'security', false ) ) { $response_data = array( 'status' => false, 'error' => __( 'Nonce validation failed', 'cartflows' ), ); wp_send_json_error( $response_data ); } ob_start(); if ( ! empty( $_POST['coupon_code'] ) ) { $result = WC()->cart->add_discount( sanitize_text_field( wp_unslash( $_POST['coupon_code'] ) ) ); } else { wc_add_notice( WC_Coupon::get_generic_coupon_error( WC_Coupon::E_WC_COUPON_PLEASE_ENTER ), 'error' ); } $response = array( 'status' => $result, 'msg' => wc_print_notices( true ), ); ob_clean(); // Clearing the uncessary echo HTML. wp_send_json( $response ); die(); } /** * Remove coupon. */ public function remove_coupon() { check_ajax_referer( 'wcf-remove-coupon', 'security' ); $coupon = isset( $_POST['coupon_code'] ) ? sanitize_text_field( wp_unslash( $_POST['coupon_code'] ) ) : false; if ( empty( $coupon ) ) { echo "