@@ -8,130 +8,130 @@ |
||
8 | 8 | */ |
9 | 9 | class Checkout { |
10 | 10 | |
11 | - /** |
|
12 | - * Holds class instance |
|
13 | - * |
|
14 | - * @since 1.0.0 |
|
15 | - * |
|
16 | - * @var object \lsx_health_plan\classes\integrations\woocommerce\Checkout() |
|
17 | - */ |
|
18 | - protected static $instance = null; |
|
11 | + /** |
|
12 | + * Holds class instance |
|
13 | + * |
|
14 | + * @since 1.0.0 |
|
15 | + * |
|
16 | + * @var object \lsx_health_plan\classes\integrations\woocommerce\Checkout() |
|
17 | + */ |
|
18 | + protected static $instance = null; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - public $plan_id = ''; |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + public $plan_id = ''; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Constructor |
|
27 | - */ |
|
28 | - public function __construct() { |
|
29 | - add_filter( 'woocommerce_order_button_text', array( $this, 'checkout_button_text' ), 10, 1 ); |
|
25 | + /** |
|
26 | + * Constructor |
|
27 | + */ |
|
28 | + public function __construct() { |
|
29 | + add_filter( 'woocommerce_order_button_text', array( $this, 'checkout_button_text' ), 10, 1 ); |
|
30 | 30 | |
31 | - // Cart Messages. |
|
32 | - add_action( 'lsx_content_wrap_before', array( $this, 'cart_notices' ) ); |
|
33 | - add_filter( 'wc_add_to_cart_message_html', array( $this, 'add_to_cart_message' ), 10, 3 ); |
|
31 | + // Cart Messages. |
|
32 | + add_action( 'lsx_content_wrap_before', array( $this, 'cart_notices' ) ); |
|
33 | + add_filter( 'wc_add_to_cart_message_html', array( $this, 'add_to_cart_message' ), 10, 3 ); |
|
34 | 34 | |
35 | - // Thank you page links. |
|
36 | - add_filter( 'woocommerce_memberships_thank_you_message', array( $this, 'memberships_thank_you_links' ), 10, 3 ); |
|
37 | - return (string) apply_filters( 'woocommerce_memberships_thank_you_message', $message, $order_id, $memberships ); |
|
38 | - } |
|
35 | + // Thank you page links. |
|
36 | + add_filter( 'woocommerce_memberships_thank_you_message', array( $this, 'memberships_thank_you_links' ), 10, 3 ); |
|
37 | + return (string) apply_filters( 'woocommerce_memberships_thank_you_message', $message, $order_id, $memberships ); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Return an instance of this class. |
|
42 | - * |
|
43 | - * @since 1.0.0 |
|
44 | - * |
|
45 | - * @return object \lsx_health_plan\classes\integrations\woocommerce\Checkout() A single instance of this class. |
|
46 | - */ |
|
47 | - public static function get_instance() { |
|
48 | - // If the single instance hasn't been set, set it now. |
|
49 | - if ( null === self::$instance ) { |
|
50 | - self::$instance = new self(); |
|
51 | - } |
|
52 | - return self::$instance; |
|
53 | - } |
|
40 | + /** |
|
41 | + * Return an instance of this class. |
|
42 | + * |
|
43 | + * @since 1.0.0 |
|
44 | + * |
|
45 | + * @return object \lsx_health_plan\classes\integrations\woocommerce\Checkout() A single instance of this class. |
|
46 | + */ |
|
47 | + public static function get_instance() { |
|
48 | + // If the single instance hasn't been set, set it now. |
|
49 | + if ( null === self::$instance ) { |
|
50 | + self::$instance = new self(); |
|
51 | + } |
|
52 | + return self::$instance; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Return the Place Order Text |
|
57 | - * |
|
58 | - * @param string $label |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - public function checkout_button_text( $label = '' ) { |
|
62 | - $label = __( 'Place order', 'lsx-health-plan' ); |
|
63 | - return $label; |
|
64 | - } |
|
55 | + /** |
|
56 | + * Return the Place Order Text |
|
57 | + * |
|
58 | + * @param string $label |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + public function checkout_button_text( $label = '' ) { |
|
62 | + $label = __( 'Place order', 'lsx-health-plan' ); |
|
63 | + return $label; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Saves the Plan ID to the cart data, so we can attach it to the order later. |
|
68 | - * |
|
69 | - * @param array $cart_item_data |
|
70 | - * @param string $product_id |
|
71 | - * @param string $variation_id |
|
72 | - * @return void |
|
73 | - */ |
|
74 | - public function add_plan_id_to_cart( $cart_item_data, $product_id, $variation_id ) { |
|
75 | - $plan_id = filter_input( INPUT_GET, 'plan_id' ); |
|
76 | - if ( empty( $plan_id ) || '' === $plan_id ) { |
|
77 | - return $cart_item_data; |
|
78 | - } |
|
79 | - $cart_item_data['plan_id'] = $plan_id; |
|
80 | - return $cart_item_data; |
|
81 | - } |
|
66 | + /** |
|
67 | + * Saves the Plan ID to the cart data, so we can attach it to the order later. |
|
68 | + * |
|
69 | + * @param array $cart_item_data |
|
70 | + * @param string $product_id |
|
71 | + * @param string $variation_id |
|
72 | + * @return void |
|
73 | + */ |
|
74 | + public function add_plan_id_to_cart( $cart_item_data, $product_id, $variation_id ) { |
|
75 | + $plan_id = filter_input( INPUT_GET, 'plan_id' ); |
|
76 | + if ( empty( $plan_id ) || '' === $plan_id ) { |
|
77 | + return $cart_item_data; |
|
78 | + } |
|
79 | + $cart_item_data['plan_id'] = $plan_id; |
|
80 | + return $cart_item_data; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Output the WooCommerce Cart Notices. |
|
85 | - * |
|
86 | - * @return void |
|
87 | - */ |
|
88 | - public function cart_notices() { |
|
89 | - if ( function_exists( 'woocommerce_output_all_notices' ) && is_post_type_archive( 'plan' ) ) { |
|
90 | - echo wp_kses_post( '<div class="col-md-12 col-sm-12 woocommerce-notices-wrapper">' ); |
|
91 | - wc_print_notices(); |
|
92 | - echo wp_kses_post( '</div>' ); |
|
93 | - } |
|
94 | - } |
|
83 | + /** |
|
84 | + * Output the WooCommerce Cart Notices. |
|
85 | + * |
|
86 | + * @return void |
|
87 | + */ |
|
88 | + public function cart_notices() { |
|
89 | + if ( function_exists( 'woocommerce_output_all_notices' ) && is_post_type_archive( 'plan' ) ) { |
|
90 | + echo wp_kses_post( '<div class="col-md-12 col-sm-12 woocommerce-notices-wrapper">' ); |
|
91 | + wc_print_notices(); |
|
92 | + echo wp_kses_post( '</div>' ); |
|
93 | + } |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Changes the add to cart message and adds our course name. |
|
98 | - * |
|
99 | - * @param string $message |
|
100 | - * @param array $products |
|
101 | - * @param boolean $show_qty |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - public function add_to_cart_message( $message, $products, $show_qty ) { |
|
105 | - if ( isset( $_GET['plan_id'] ) ) { // @codingStandardsIgnoreLine. |
|
106 | - $this->plan_id = sanitize_text_field( wp_slash( $_GET['plan_id'] ) ); // @codingStandardsIgnoreLine. |
|
96 | + /** |
|
97 | + * Changes the add to cart message and adds our course name. |
|
98 | + * |
|
99 | + * @param string $message |
|
100 | + * @param array $products |
|
101 | + * @param boolean $show_qty |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + public function add_to_cart_message( $message, $products, $show_qty ) { |
|
105 | + if ( isset( $_GET['plan_id'] ) ) { // @codingStandardsIgnoreLine. |
|
106 | + $this->plan_id = sanitize_text_field( wp_slash( $_GET['plan_id'] ) ); // @codingStandardsIgnoreLine. |
|
107 | 107 | |
108 | - $title = '<strong>' . get_the_title( $this->plan_id ) . '</strong>'; |
|
109 | - $title = sprintf( _n( '%s has been added to your cart.', '%s have been added to your cart.', 1, 'lsx-health-plan' ), $title ); |
|
108 | + $title = '<strong>' . get_the_title( $this->plan_id ) . '</strong>'; |
|
109 | + $title = sprintf( _n( '%s has been added to your cart.', '%s have been added to your cart.', 1, 'lsx-health-plan' ), $title ); |
|
110 | 110 | |
111 | - // Output success messages. |
|
112 | - if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) { |
|
113 | - $return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wc_get_raw_referer() ? wp_validate_redirect( wc_get_raw_referer(), false ) : wc_get_page_permalink( 'shop' ) ); |
|
114 | - $message = sprintf( '<a href="%s" tabindex="1" class="btn button wc-forward">%s</a> %s', esc_url( $return_to ), esc_html__( 'Continue shopping', 'lsx-health-plan' ), $title ); |
|
115 | - } else { |
|
116 | - $message = sprintf( '<a href="%s" tabindex="1" class="btn button wc-forward">%s</a> %s', esc_url( wc_get_cart_url() ), esc_html__( 'View cart', 'lsx-health-plan' ), $title ); |
|
117 | - } |
|
118 | - } |
|
119 | - return $message; |
|
120 | - } |
|
111 | + // Output success messages. |
|
112 | + if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) { |
|
113 | + $return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wc_get_raw_referer() ? wp_validate_redirect( wc_get_raw_referer(), false ) : wc_get_page_permalink( 'shop' ) ); |
|
114 | + $message = sprintf( '<a href="%s" tabindex="1" class="btn button wc-forward">%s</a> %s', esc_url( $return_to ), esc_html__( 'Continue shopping', 'lsx-health-plan' ), $title ); |
|
115 | + } else { |
|
116 | + $message = sprintf( '<a href="%s" tabindex="1" class="btn button wc-forward">%s</a> %s', esc_url( wc_get_cart_url() ), esc_html__( 'View cart', 'lsx-health-plan' ), $title ); |
|
117 | + } |
|
118 | + } |
|
119 | + return $message; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Replaces the links on the thank you page. |
|
124 | - * |
|
125 | - * @param string $message |
|
126 | - * @param int $order_id |
|
127 | - * @param object $memberships |
|
128 | - * @return string |
|
129 | - */ |
|
130 | - public function memberships_thank_you_links( $message, $order_id, $memberships ) { |
|
131 | - $plan_slug = \lsx_health_plan\functions\get_option( 'my_plan_slug', false ); |
|
132 | - if ( false !== $plan_slug && '' !== $plan_slug ) { |
|
133 | - $message = preg_replace( '/<a(.*)href="([^"]*)"(.*)>/', '<a$1href="' . home_url( $plan_slug ) . '"$3>', $message ); |
|
134 | - } |
|
135 | - return $message; |
|
136 | - } |
|
122 | + /** |
|
123 | + * Replaces the links on the thank you page. |
|
124 | + * |
|
125 | + * @param string $message |
|
126 | + * @param int $order_id |
|
127 | + * @param object $memberships |
|
128 | + * @return string |
|
129 | + */ |
|
130 | + public function memberships_thank_you_links( $message, $order_id, $memberships ) { |
|
131 | + $plan_slug = \lsx_health_plan\functions\get_option( 'my_plan_slug', false ); |
|
132 | + if ( false !== $plan_slug && '' !== $plan_slug ) { |
|
133 | + $message = preg_replace( '/<a(.*)href="([^"]*)"(.*)>/', '<a$1href="' . home_url( $plan_slug ) . '"$3>', $message ); |
|
134 | + } |
|
135 | + return $message; |
|
136 | + } |
|
137 | 137 | } |
@@ -26,15 +26,15 @@ discard block |
||
26 | 26 | * Constructor |
27 | 27 | */ |
28 | 28 | public function __construct() { |
29 | - add_filter( 'woocommerce_order_button_text', array( $this, 'checkout_button_text' ), 10, 1 ); |
|
29 | + add_filter('woocommerce_order_button_text', array($this, 'checkout_button_text'), 10, 1); |
|
30 | 30 | |
31 | 31 | // Cart Messages. |
32 | - add_action( 'lsx_content_wrap_before', array( $this, 'cart_notices' ) ); |
|
33 | - add_filter( 'wc_add_to_cart_message_html', array( $this, 'add_to_cart_message' ), 10, 3 ); |
|
32 | + add_action('lsx_content_wrap_before', array($this, 'cart_notices')); |
|
33 | + add_filter('wc_add_to_cart_message_html', array($this, 'add_to_cart_message'), 10, 3); |
|
34 | 34 | |
35 | 35 | // Thank you page links. |
36 | - add_filter( 'woocommerce_memberships_thank_you_message', array( $this, 'memberships_thank_you_links' ), 10, 3 ); |
|
37 | - return (string) apply_filters( 'woocommerce_memberships_thank_you_message', $message, $order_id, $memberships ); |
|
36 | + add_filter('woocommerce_memberships_thank_you_message', array($this, 'memberships_thank_you_links'), 10, 3); |
|
37 | + return (string) apply_filters('woocommerce_memberships_thank_you_message', $message, $order_id, $memberships); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public static function get_instance() { |
48 | 48 | // If the single instance hasn't been set, set it now. |
49 | - if ( null === self::$instance ) { |
|
49 | + if (null === self::$instance) { |
|
50 | 50 | self::$instance = new self(); |
51 | 51 | } |
52 | 52 | return self::$instance; |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | * @param string $label |
59 | 59 | * @return void |
60 | 60 | */ |
61 | - public function checkout_button_text( $label = '' ) { |
|
62 | - $label = __( 'Place order', 'lsx-health-plan' ); |
|
61 | + public function checkout_button_text($label = '') { |
|
62 | + $label = __('Place order', 'lsx-health-plan'); |
|
63 | 63 | return $label; |
64 | 64 | } |
65 | 65 | |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | * @param string $variation_id |
72 | 72 | * @return void |
73 | 73 | */ |
74 | - public function add_plan_id_to_cart( $cart_item_data, $product_id, $variation_id ) { |
|
75 | - $plan_id = filter_input( INPUT_GET, 'plan_id' ); |
|
76 | - if ( empty( $plan_id ) || '' === $plan_id ) { |
|
74 | + public function add_plan_id_to_cart($cart_item_data, $product_id, $variation_id) { |
|
75 | + $plan_id = filter_input(INPUT_GET, 'plan_id'); |
|
76 | + if (empty($plan_id) || '' === $plan_id) { |
|
77 | 77 | return $cart_item_data; |
78 | 78 | } |
79 | 79 | $cart_item_data['plan_id'] = $plan_id; |
@@ -86,10 +86,10 @@ discard block |
||
86 | 86 | * @return void |
87 | 87 | */ |
88 | 88 | public function cart_notices() { |
89 | - if ( function_exists( 'woocommerce_output_all_notices' ) && is_post_type_archive( 'plan' ) ) { |
|
90 | - echo wp_kses_post( '<div class="col-md-12 col-sm-12 woocommerce-notices-wrapper">' ); |
|
89 | + if (function_exists('woocommerce_output_all_notices') && is_post_type_archive('plan')) { |
|
90 | + echo wp_kses_post('<div class="col-md-12 col-sm-12 woocommerce-notices-wrapper">'); |
|
91 | 91 | wc_print_notices(); |
92 | - echo wp_kses_post( '</div>' ); |
|
92 | + echo wp_kses_post('</div>'); |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
@@ -101,19 +101,19 @@ discard block |
||
101 | 101 | * @param boolean $show_qty |
102 | 102 | * @return string |
103 | 103 | */ |
104 | - public function add_to_cart_message( $message, $products, $show_qty ) { |
|
105 | - if ( isset( $_GET['plan_id'] ) ) { // @codingStandardsIgnoreLine. |
|
106 | - $this->plan_id = sanitize_text_field( wp_slash( $_GET['plan_id'] ) ); // @codingStandardsIgnoreLine. |
|
104 | + public function add_to_cart_message($message, $products, $show_qty) { |
|
105 | + if (isset($_GET['plan_id'])) { // @codingStandardsIgnoreLine. |
|
106 | + $this->plan_id = sanitize_text_field(wp_slash($_GET['plan_id'])); // @codingStandardsIgnoreLine. |
|
107 | 107 | |
108 | - $title = '<strong>' . get_the_title( $this->plan_id ) . '</strong>'; |
|
109 | - $title = sprintf( _n( '%s has been added to your cart.', '%s have been added to your cart.', 1, 'lsx-health-plan' ), $title ); |
|
108 | + $title = '<strong>' . get_the_title($this->plan_id) . '</strong>'; |
|
109 | + $title = sprintf(_n('%s has been added to your cart.', '%s have been added to your cart.', 1, 'lsx-health-plan'), $title); |
|
110 | 110 | |
111 | 111 | // Output success messages. |
112 | - if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) { |
|
113 | - $return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wc_get_raw_referer() ? wp_validate_redirect( wc_get_raw_referer(), false ) : wc_get_page_permalink( 'shop' ) ); |
|
114 | - $message = sprintf( '<a href="%s" tabindex="1" class="btn button wc-forward">%s</a> %s', esc_url( $return_to ), esc_html__( 'Continue shopping', 'lsx-health-plan' ), $title ); |
|
112 | + if ('yes' === get_option('woocommerce_cart_redirect_after_add')) { |
|
113 | + $return_to = apply_filters('woocommerce_continue_shopping_redirect', wc_get_raw_referer() ? wp_validate_redirect(wc_get_raw_referer(), false) : wc_get_page_permalink('shop')); |
|
114 | + $message = sprintf('<a href="%s" tabindex="1" class="btn button wc-forward">%s</a> %s', esc_url($return_to), esc_html__('Continue shopping', 'lsx-health-plan'), $title); |
|
115 | 115 | } else { |
116 | - $message = sprintf( '<a href="%s" tabindex="1" class="btn button wc-forward">%s</a> %s', esc_url( wc_get_cart_url() ), esc_html__( 'View cart', 'lsx-health-plan' ), $title ); |
|
116 | + $message = sprintf('<a href="%s" tabindex="1" class="btn button wc-forward">%s</a> %s', esc_url(wc_get_cart_url()), esc_html__('View cart', 'lsx-health-plan'), $title); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | return $message; |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | * @param object $memberships |
128 | 128 | * @return string |
129 | 129 | */ |
130 | - public function memberships_thank_you_links( $message, $order_id, $memberships ) { |
|
131 | - $plan_slug = \lsx_health_plan\functions\get_option( 'my_plan_slug', false ); |
|
132 | - if ( false !== $plan_slug && '' !== $plan_slug ) { |
|
133 | - $message = preg_replace( '/<a(.*)href="([^"]*)"(.*)>/', '<a$1href="' . home_url( $plan_slug ) . '"$3>', $message ); |
|
130 | + public function memberships_thank_you_links($message, $order_id, $memberships) { |
|
131 | + $plan_slug = \lsx_health_plan\functions\get_option('my_plan_slug', false); |
|
132 | + if (false !== $plan_slug && '' !== $plan_slug) { |
|
133 | + $message = preg_replace('/<a(.*)href="([^"]*)"(.*)>/', '<a$1href="' . home_url($plan_slug) . '"$3>', $message); |
|
134 | 134 | } |
135 | 135 | return $message; |
136 | 136 | } |