1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
<?php
namespace Objectiv\Plugins\Checkout\Action;
/** * Class ApplyCouponAction * * @link checkoutwc.com * @since 1.0.0 * @package Objectiv\Plugins\Checkout\Action * @author Brandon Tassone <[email protected]> */ class RemoveCouponAction extends CFWAction {
/** * ApplyCouponAction constructor. * * @since 1.0.0 * @access public */ public function __construct() { parent::__construct( 'cfw_remove_coupon', false ); }
/** * Applies the coupon discount and returns the new totals * * @since 1.0.0 * @access public */ public function action() { check_ajax_referer( 'remove-coupon', 'security' );
$coupon = isset( $_POST['coupon_code'] ) ? wc_format_coupon_code( wp_unslash( $_POST['coupon_code'] ) ) : false; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $result = false;
ob_start();
if ( empty( $coupon ) ) { wc_add_notice( cfw__( 'Sorry there was a problem removing this coupon.', 'woocommerce' ), 'error' ); } else { WC()->cart->remove_coupon( $coupon ); wc_add_notice( cfw__( 'Coupon has been removed.', 'woocommerce' ) ); $result = true; }
$output = ob_get_clean();
$this->out( /** * Filters remove coupon action response object * * @since 3.14.0 * * @param array $response The response object */ apply_filters( 'cfw_remove_coupon_response', array( 'result' => $result, 'html' => $output, 'coupon' => $coupon, ) ) ); } }
|