PluginProbe
Additional Terms Lite for WooCommerce / 1.1.0
Additional Terms Lite for WooCommerce v1.1.0
1.7.3 1.7.2.1 trunk 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.6.3 All 35 releases
woo-additional-terms / woo-additioanl-terms.php

woo-additioanl-terms.php in Additional Terms Lite for WooCommerce 1.1.0, at woo-additioanl-terms.php

196 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Woo Additional Terms
4 Plugin URI: https://www.mypreview.one
5 Description: Add additional terms and condition checkbox into WooCommerce Checkout.
6 Version: 1.1.0
7 Author: MyPreview
8 Author URI: https://www.mypreview.one
9 Text Domain: woo-additional-terms
10 Domain Path: /languages
11 License: GPL3
12 License URI: https://www.gnu.org/licenses/gpl-3.0.html
13 WC requires at least: 3.3.1
14 WC tested up to: 3.4.2
15
16 "Woo Additional Terms" is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with "Woo Additional Terms". If not, see https://www.gnu.org/licenses/gpl-3.0.html.
23 */
24
25 class Woo_Additional_Terms {
26 /**
27 * Bootstraps the class and hooks required actions & filters.
28 *
29 */
30 public static function init() {
31
32 add_action( 'plugins_loaded', __CLASS__ . '::plugins_loaded', 10 );
33 add_filter( 'woocommerce_settings_tabs_array', __CLASS__ . '::add_settings_tab', 50 );
34 add_action( 'woocommerce_settings_tabs_settings_tab_wat', __CLASS__ . '::settings_tab' );
35 add_action( 'woocommerce_update_options_settings_tab_wat', __CLASS__ . '::update_settings' );
36 add_action( 'woocommerce_review_order_before_submit', __CLASS__ . '::checkout_checkbox' );
37 add_action( 'woocommerce_checkout_process', __CLASS__ . '::notice_error' );
38
39 }
40
41 public static function plugins_loaded() {
42
43 load_plugin_textdomain( 'woo-additional-terms', FALSE, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
44
45 if ( ! class_exists( 'WooCommerce' ) ) {
46 add_action( 'admin_notices', __CLASS__ . '::wc_install_notice', 99 );
47 return;
48 } // End If Statement
49
50 }
51
52 public static function wc_install_notice() {
53
54 /* translators: 1. URL link. */
55 echo '<div class="error"><p><strong>' . sprintf( esc_html__( 'Woo Additional Terms requires WooCommerce to be installed and active. You can download %s here.', 'woo-additional-terms' ), '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>' ) . '</strong></p></div>';
56
57 }
58
59 /**
60 * Add a new settings tab to the WooCommerce settings tabs array.
61 *
62 * @param array $settings_tabs Array of WooCommerce setting tabs & their labels, excluding the Subscription tab.
63 * @return array $settings_tabs Array of WooCommerce setting tabs & their labels, including the Subscription tab.
64 */
65 public static function add_settings_tab( $settings_tabs ) {
66
67 $settings_tabs['settings_tab_wat'] = __( 'Additional Terms', 'woo-additional-terms' );
68
69 return $settings_tabs;
70
71 }
72 /**
73 * Uses the WooCommerce admin fields API to output settings via the @see woocommerce_admin_fields() function.
74 *
75 * @uses woocommerce_admin_fields()
76 * @uses self::get_settings()
77 */
78 public static function settings_tab() {
79
80 woocommerce_admin_fields( self::get_settings() );
81
82 }
83 /**
84 * Uses the WooCommerce options API to save settings via the @see woocommerce_update_options() function.
85 *
86 * @uses woocommerce_update_options()
87 * @uses self::get_settings()
88 */
89 public static function update_settings() {
90
91 woocommerce_update_options( self::get_settings() );
92
93 }
94 /**
95 * Get all the settings for this plugin for @see woocommerce_admin_fields() function.
96 *
97 * @return array Array of settings for @see woocommerce_admin_fields() function.
98 */
99 public static function get_settings() {
100 $settings = array(
101 'section_title' => array(
102 'name' => __( 'Terms and Conditions', 'woo-additional-terms' ),
103 'type' => 'title',
104 'desc' => 'This section controls the display of your additional terms and condition fieldset.',
105 'id' => 'wc_settings_tab_wat_section_title'
106 ),
107 'page_id' => array(
108 'name' => __( 'Additional Terms', 'woo-additional-terms' ),
109 'desc' => __( 'Choose a page to act as your additional terms and condition.', 'woo-additional-terms' ),
110 'type' => 'single_select_page',
111 'class' => 'wc-enhanced-select-nostd',
112 'css' => 'min-width:300px;',
113 'id' => 'wc_settings_tab_wat_section_page_id',
114 'desc_tip' => TRUE,
115 'autoload' => FALSE
116 ),
117 'notice' => array(
118 'name' => __( 'Notice', 'woo-additional-terms' ),
119 'desc' => __( 'Optionally add some text about your store privacy policy to show during checkout.', 'woo-additional-terms' ),
120 'default' => __( 'I have read and agree to the website [additional-terms]', 'woo-additional-terms' ),
121 'type' => 'textarea',
122 'css' => 'min-width:300px;',
123 'id' => 'wc_settings_tab_wat_section_notice',
124 'desc_tip' => TRUE,
125 'autoload' => FALSE
126 ),
127 'error' => array(
128 'name' => __( 'Error', 'woo-additional-terms' ),
129 'desc' => __( 'Display friendly notice whenever customer doesn\'t accept additional terms.', 'woo-additional-terms' ),
130 'default' => __( 'You must accept our additional terms.', 'woo-additional-terms' ),
131 'type' => 'text',
132 'css' => 'min-width:300px;',
133 'id' => 'wc_settings_tab_wat_section_notice_error',
134 'desc_tip' => TRUE,
135 'autoload' => FALSE
136 ),
137 'section_end' => array(
138 'type' => 'sectionend',
139 'id' => 'wc_settings_tab_wat_section_end'
140 )
141 );
142
143 return apply_filters( 'wc_settings_tab_wat_settings', $settings );
144
145 }
146
147 /**
148 * Display additional terms and condition checkbox on checkout page before the submit (place order) button.
149 *
150 * @return void @see woocommerce_form_field() function.
151 */
152 public static function checkout_checkbox() {
153
154 $page_id = (int) get_option( 'wc_settings_tab_wat_section_page_id' );
155 $notice = (string) get_option( 'wc_settings_tab_wat_section_notice' );
156
157 // Bail out, if the page ID is not defined yet!
158 if ( ! isset( $page_id ) || empty( $page_id ) ) {
159 return NULL;
160 } // End If Statement
161
162 if ( FALSE !== strpos( $notice, '[additional-terms]' ) ) {
163
164 $notice = str_replace( '[additional-terms]', '<a href="' . esc_url( get_permalink( $page_id ) ) . '" target="_blank"> ' . esc_html( get_the_title( $page_id ) ) . '</a>', $notice );
165
166 } // End If Statement
167
168 woocommerce_form_field( 'woo_additional_terms', array(
169 'type' => 'checkbox',
170 'class' => array( 'form-row woo-additional-terms' ),
171 'label_class' => array( 'woocommerce-form__label woocommerce-form__label-for-checkbox checkbox' ),
172 'input_class' => array( 'woocommerce-form__input woocommerce-form__input-checkbox input-checkbox' ),
173 'required' => TRUE,
174 'label' => wp_kses_post( $notice )
175 ) );
176
177 }
178
179 /**
180 * Show notice if customer does not accept additional terms and conditions.
181 *
182 * @return void @see wc_add_notice() function.
183 */
184 public static function notice_error() {
185
186 $error = (string) get_option( 'wc_settings_tab_wat_section_notice_error' );
187
188 if ( ! (int) isset( $_POST['woo_additional_terms'] ) ) {
189 wc_add_notice( $error, 'error' );
190 } // End If Statement
191
192 }
193
194 }
195
196 Woo_Additional_Terms::init();