diff --git a/assets/js/admin.js b/assets/js/admin.js index 591c43e..9a3cc1e 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -11,26 +11,40 @@ cache() { this.vars = {}; this.vars.rate = '#woo-additional-terms-dismiss-rate .notice-dismiss'; + this.vars.rate += ', #woo-additional-terms-dismiss-rate .notice-dismiss-later'; + this.vars.rated = '#woo-additional-terms-dismiss-rate .notice-dismiss-rated'; this.vars.upsell = '#woo-additional-terms-dismiss-upsell .notice-dismiss'; }, init() { this.cache(); - $( document.body ).on( 'click', this.vars.rate, ( event ) => this.handleOnDismiss( event, 'rate' ) ); - $( document.body ).on( 'click', this.vars.upsell, ( event ) => this.handleOnDismiss( event, 'upsell' ) ); + this.bindEvents(); + }, + + bindEvents() { + $( document.body ) + .on( 'click', this.vars.rate, ( event ) => this.handleOnDismiss( event, 'rate' ) ) + .on( 'click', this.vars.rated, ( event ) => this.handleOnDismiss( event, 'rated' ) ) + .on( 'click', this.vars.upsell, ( event ) => this.handleOnDismiss( event, 'upsell' ) ); }, handleOnDismiss( event, action ) { - event.preventDefault(); + const $this = $( event.target ); + + if ( ! $this.attr( 'href' ) ) { + event.preventDefault(); + } $.ajax( { type: 'POST', url: ajaxurl, + dataType: 'json', data: { _ajax_nonce: watVars.dismiss_nonce, action: `woo_additional_terms_dismiss_${ action }`, }, - dataType: 'json', + } ).always( () => { + $this.closest( 'div.notice:visible' ).slideUp(); } ); }, }; diff --git a/assets/js/minified/admin.js b/assets/js/minified/admin.js index ffae902..5d8d839 100644 --- a/assets/js/minified/admin.js +++ b/assets/js/minified/admin.js @@ -1 +1 @@ -"use strict";(function(wp,$){"use strict";if(!wp){return}var watAdmin={cache:function cache(){this.vars={};this.vars.rate="#woo-additional-terms-dismiss-rate .notice-dismiss";this.vars.upsell="#woo-additional-terms-dismiss-upsell .notice-dismiss"},init:function init(){var _this=this;this.cache();$(document.body).on("click",this.vars.rate,function(event){return _this.handleOnDismiss(event,"rate")});$(document.body).on("click",this.vars.upsell,function(event){return _this.handleOnDismiss(event,"upsell")})},handleOnDismiss:function handleOnDismiss(event,action){event.preventDefault();$.ajax({type:"POST",url:ajaxurl,data:{_ajax_nonce:watVars.dismiss_nonce,action:"woo_additional_terms_dismiss_".concat(action)},dataType:"json"})}};watAdmin.init()})(window.wp,jQuery); \ No newline at end of file +"use strict";(function(wp,$){"use strict";if(!wp){return}var watAdmin={cache:function cache(){this.vars={};this.vars.rate="#woo-additional-terms-dismiss-rate .notice-dismiss";this.vars.rate+=", #woo-additional-terms-dismiss-rate .notice-dismiss-later";this.vars.rated="#woo-additional-terms-dismiss-rate .notice-dismiss-rated";this.vars.upsell="#woo-additional-terms-dismiss-upsell .notice-dismiss"},init:function init(){this.cache();this.bindEvents()},bindEvents:function bindEvents(){var _this=this;$(document.body).on("click",this.vars.rate,function(event){return _this.handleOnDismiss(event,"rate")}).on("click",this.vars.rated,function(event){return _this.handleOnDismiss(event,"rated")}).on("click",this.vars.upsell,function(event){return _this.handleOnDismiss(event,"upsell")})},handleOnDismiss:function handleOnDismiss(event,action){var $this=$(event.target);if(!$this.attr("href")){event.preventDefault()}$.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{_ajax_nonce:watVars.dismiss_nonce,action:"woo_additional_terms_dismiss_".concat(action)}}).always(function(){$this.closest("div.notice:visible").slideUp()})}};watAdmin.init()})(window.wp,jQuery); \ No newline at end of file diff --git a/includes/class-wat-checkout-block-integration.php b/includes/class-wat-checkout-block-integration.php index 9392040..78dcea4 100644 --- a/includes/class-wat-checkout-block-integration.php +++ b/includes/class-wat-checkout-block-integration.php @@ -2,12 +2,15 @@ /** * Register the "Additional Terms" block for use in the Checkout Block offered by "WooCommerce Blocks". * - * @link https://mypreview.one/woo-additional-terms - * @author MyPreview (Github: @mahdiyazdani, @gooklani, @mypreview) - * @since 1.5.0 + * @link https://mypreview.one/woo-additional-terms * - * @package woo-additional-terms - * @subpackage woo-additional-terms/includes + * @author MyPreview (Github: @mahdiyazdani, @gooklani, @mypreview) + * + * @since 1.5.0 + * + * @package woo-additional-terms + * + * @subpackage woo-additional-terms/includes */ use Automattic\WooCommerce\Blocks\Integrations\IntegrationInterface; @@ -27,24 +30,29 @@ class WAT_Checkout_Block_Integration implements IntegrationInterface { /** * The name of the integration. * - * @since 1.5.0 - * @return string + * @since 1.5.0 + * + * @return string */ public function get_name() { + return '_woo_additional_terms'; } /** * When called invokes any initialization/setup for the integration. * - * @since 1.5.0 - * @return void + * @since 1.5.0 + * + * @return void */ public function initialize() { + $this->register_frontend_scripts(); $this->register_editor_scripts(); $this->register_editor_blocks(); $this->extend_store_api(); + add_filter( '__experimental_woocommerce_blocks_add_data_attributes_to_block', array( $this, 'add_attributes_to_frontend_blocks' ) ); add_action( 'woocommerce_store_api_checkout_update_order_from_request', array( $this, 'save_terms_acceptance' ), 10, 2 ); } @@ -52,63 +60,81 @@ public function initialize() { /** * Registers all the static resources for the front-end. * - * @since 1.5.0 - * @return void + * @since 1.5.0 + * + * @return void */ public function register_frontend_scripts() { - wp_register_script( WOO_ADDITIONAL_TERMS_SLUG . '-checkout', trailingslashit( WOO_ADDITIONAL_TERMS_DIR_URL ) . 'assets/js/' . WOO_ADDITIONAL_TERMS_MIN_DIR . 'checkout.js', array( 'react', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wc-blocks-data-store', 'wc-blocks-checkout', 'wc-settings' ), WOO_ADDITIONAL_TERMS_VERSION, true ); + + wp_register_script( Woo_Additional_Terms::SLUG . '-checkout', trailingslashit( WOO_ADDITIONAL_TERMS_DIR_URL ) . 'assets/js/' . WOO_ADDITIONAL_TERMS_MIN_DIR . 'checkout.js', array( 'react', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wc-blocks-data-store', 'wc-blocks-checkout', 'wc-settings' ), WOO_ADDITIONAL_TERMS_VERSION, true ); } /** * Registers all the static resources for the editor. * - * @since 1.5.0 - * @return void + * @since 1.5.0 + * + * @return void */ public function register_editor_scripts() { - wp_register_script( WOO_ADDITIONAL_TERMS_SLUG . '-editor', trailingslashit( WOO_ADDITIONAL_TERMS_DIR_URL ) . 'assets/js/' . WOO_ADDITIONAL_TERMS_MIN_DIR . 'block.js', array( 'react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives', 'wc-blocks-checkout', 'wc-settings' ), WOO_ADDITIONAL_TERMS_VERSION, true ); + + wp_register_script( Woo_Additional_Terms::SLUG . '-editor', trailingslashit( WOO_ADDITIONAL_TERMS_DIR_URL ) . 'assets/js/' . WOO_ADDITIONAL_TERMS_MIN_DIR . 'block.js', array( 'react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives', 'wc-blocks-checkout', 'wc-settings' ), WOO_ADDITIONAL_TERMS_VERSION, true ); } /** * Returns an array containing the handles of any scripts registered by our extension. * - * @since 1.5.0 - * @return array + * @since 1.5.0 + * + * @return array */ public function get_script_handles() { - return array( WOO_ADDITIONAL_TERMS_SLUG . '-checkout' ); + + return array( Woo_Additional_Terms::SLUG . '-checkout' ); } /** * Returns an array containing the handles of any editor scripts registered by our extension. * - * @since 1.5.0 - * @return array + * @since 1.5.0 + * + * @return array */ public function get_editor_script_handles() { - return array( WOO_ADDITIONAL_TERMS_SLUG . '-editor' ); + + return array( Woo_Additional_Terms::SLUG . '-editor' ); } /** * Returns an associative array containing any data we want to be available to the scripts on the front-end. * - * @since 1.5.0 - * @return array + * @since 1.5.0 + * + * @return array */ public function get_script_data() { - $notice = (string) get_option( '_woo_additional_terms_notice', '' ); + + $notice = get_option( '_woo_additional_terms_notice', '' ); $page_id = get_option( '_woo_additional_terms_page_id', null ); if ( - $page_id - && ! empty( $page_id ) + ! empty( $page_id ) && ! empty( $notice ) - && false !== strpos( $notice, '[additional-terms]' ) + && false !== strpos( $notice, Woo_Additional_Terms::SHORTCODE ) + && get_post( $page_id ) ) { - $notice = str_replace( '[additional-terms]', sprintf( '%s', esc_url( get_permalink( $page_id ) ), esc_html( get_the_title( $page_id ) ) ), $notice ); + $notice = str_replace( + Woo_Additional_Terms::SHORTCODE, + sprintf( + '%s', + esc_url( get_permalink( $page_id ) ), + wp_kses_post( get_the_title( $page_id ) ) + ), + $notice + ); } - $data = array( + return array( 'notice' => wp_kses( $notice, array( @@ -122,27 +148,30 @@ public function get_script_data() { ), 'content' => Woo_Additional_Terms::terms_page_content( $page_id, false ), ); - - return $data; } /** * Register editor block. * - * @since 1.5.0 - * @return void + * @since 1.5.0 + * + * @return void */ public function register_editor_blocks() {} /** * This allows dynamic (JS) blocks to access attributes in the frontend. * - * @since 1.5.0 - * @param array $allowed_blocks List of allowed blocks. - * @return array + * @since 1.5.0 + * + * @param array $allowed_blocks List of allowed blocks. + * + * @return array */ public function add_attributes_to_frontend_blocks( $allowed_blocks ) { + $allowed_blocks[] = 'mypreview/woo-additional-terms'; + return $allowed_blocks; } @@ -150,22 +179,28 @@ public function add_attributes_to_frontend_blocks( $allowed_blocks ) { * Fires after an order saved into the database. * We will update the post meta * - * @since 1.5.0 - * @param WC_Order $order Order ID or order object. - * @param WP_REST_Request $request The API request currently being processed. - * @return void + * @since 1.5.0 + * + * @param WC_Order $order Order ID or order object. + * @param WP_REST_Request $request The API request currently being processed. + * + * @return void + * * @phpcs:disable WordPress.Security.NonceVerification.Missing */ public function save_terms_acceptance( $order, $request ) { - $acceptance = null; - if ( isset( $request['extensions'], $request['extensions']['_woo_additional_terms'], $request['extensions']['_woo_additional_terms']['wat_checkbox'] ) ) { - $acceptance = '1'; + if ( ! isset( $request['extensions'], $request['extensions']['_woo_additional_terms'], $request['extensions']['_woo_additional_terms']['wat_checkbox'] ) ) { + return; } - if ( $acceptance ) { - $order->update_meta_data( '_woo_additional_terms', $acceptance ); - } + $order->update_meta_data( + '_woo_additional_terms', + array( + 'id' => wc_clean( get_option( '_woo_additional_terms_page_id', null ) ), + 'notice' => wc_clean( get_option( '_woo_additional_terms_notice', '' ) ), + ) + ); } /** @@ -173,8 +208,9 @@ public function save_terms_acceptance( $order, $request ) { * Registers the checkout endpoint extension to inform our frontend component about the result of * the validity of the additional terms checkbox and react accordingly. * - * @since 1.5.0 - * @return void + * @since 1.5.0 + * + * @return void */ public function extend_store_api() { $extend = StoreApi::container()->get( @@ -186,16 +222,19 @@ public function extend_store_api() { 'endpoint' => CheckoutSchema::IDENTIFIER, 'namespace' => $this->get_name(), 'schema_callback' => function() { + return array( 'wat_checkbox' => array( 'type' => 'boolean', 'context' => array(), 'arg_options' => array( 'validate_callback' => function( $value ) { + if ( ! is_bool( $value ) ) { /* translators: %s: Render the type of the variable. */ return new \WP_Error( 'api-error', sprintf( esc_html__( 'Value of field %s was posted with incorrect data type.', 'woo-additional-terms' ), gettype( $value ) ) ); } + return true; }, ), diff --git a/languages/woo-additional-terms.pot b/languages/woo-additional-terms.pot index 4c97ea1..1569e25 100644 --- a/languages/woo-additional-terms.pot +++ b/languages/woo-additional-terms.pot @@ -2,14 +2,14 @@ # This file is distributed under the GPL-3.0. msgid "" msgstr "" -"Project-Id-Version: Woo Additional Terms 1.5.1\n" +"Project-Id-Version: Woo Additional Terms 1.5.2\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/woo-additional-terms\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2023-02-17T09:10:49+00:00\n" +"POT-Creation-Date: 2023-04-06T17:48:33+00:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "X-Generator: WP-CLI 2.7.1\n" "X-Domain: woo-additional-terms\n" @@ -24,7 +24,7 @@ msgid "https://mypreview.one/woo-additional-terms" msgstr "" #. Description of the plugin -msgid "Add additional terms and condition checkbox to the WooCommerce checkout." +msgid "Add additional terms and conditions checkbox to your WooCommerce checkout page." msgstr "" #. Author of the plugin @@ -32,205 +32,286 @@ msgid "MyPreview" msgstr "" #. translators: %s: Render the type of the variable. -#: includes/class-wat-checkout-block-integration.php:197 +#: includes/class-wat-checkout-block-integration.php:235 msgid "Value of field %s was posted with incorrect data type." msgstr "" -#: woo-additioanl-terms.php:141 +#: woo-additioanl-terms.php:175 msgctxt "clone" msgid "Cloning instances of this class is forbidden." msgstr "" -#: woo-additioanl-terms.php:151 +#: woo-additioanl-terms.php:187 msgctxt "wakeup" msgid "Unserializing instances of this class is forbidden." msgstr "" #. translators: 1: Dashicon, Open anchor tag, 2: Close anchor tag. -#: woo-additioanl-terms.php:200 +#: woo-additioanl-terms.php:243 msgctxt "admin notice" msgid "%1$s requires the following plugin: %2$sWooCommerce%3$s" msgstr "" -#. translators: 1: HTML Symbol, 2: HTML symbol, 3: Open anchor tag, 4: Close anchor tag. -#: woo-additioanl-terms.php:212 +#: woo-additioanl-terms.php:279 msgctxt "admin notice" -msgid "%1$s Add unlimited “I Agree with terms & conditions” checkboxes to the WooCommerce checkout without any manual effort needed. %2$s %3$sUpgrade to PRO%4$s" +msgid "Upgrade to Woo Additional Terms PRO" msgstr "" -#. translators: 1: HTML symbol, 2: Plugin name, 3: Activation duration, 4: HTML symbol, 5: Open anchor tag, 6: Close anchor tag. -#: woo-additioanl-terms.php:216 +#: woo-additioanl-terms.php:283 msgctxt "admin notice" -msgid "%1$s You have been using the %2$s plugin for %3$s now, do you like it as much as we like you? %4$s %5$sRate 5-Stars%6$s" +msgid "Unlock the full potential of the plugin. Enjoy unlimited custom terms and conditions checkboxes, flexible display options, advanced conditional logic, and more." msgstr "" -#: woo-additioanl-terms.php:271 +#: woo-additioanl-terms.php:286 +msgctxt "admin notice" +msgid "Upgrade now to access advanced features and improve customer trust!" +msgstr "" + +#: woo-additioanl-terms.php:290 +msgctxt "admin notice" +msgid "Go PRO for More Options" +msgstr "" + +#. translators: 1: Activation duration, 2: Plugin name +#: woo-additioanl-terms.php:307 +msgctxt "admin notice" +msgid "%1$s have passed since you started using %2$s." +msgstr "" + +#: woo-additioanl-terms.php:315 +msgctxt "admin notice" +msgid "Would you kindly consider leaving a review and letting us know how the plugin has helped your business? Your feedback is greatly appreciated!" +msgstr "" + +#: woo-additioanl-terms.php:320 +msgctxt "admin notice" +msgid "Give 5 Stars" +msgstr "" + +#: woo-additioanl-terms.php:323 +msgctxt "admin notice" +msgid "Maybe later" +msgstr "" + +#: woo-additioanl-terms.php:326 +msgctxt "admin notice" +msgid "I already did!" +msgstr "" + +#: woo-additioanl-terms.php:413 msgctxt "tab title" msgid "Additional Terms" msgstr "" -#: woo-additioanl-terms.php:307 +#: woo-additioanl-terms.php:461 msgctxt "upsell" -msgid "Add terms & conditions checkboxes and protect your business by requiring the acknowledgment of rules." +msgid "Upgrade to Woo Additional Terms PRO for More Control Over Your Store’s Policies" msgstr "" -#: woo-additioanl-terms.php:310 +#: woo-additioanl-terms.php:464 msgctxt "upsell" -msgid "Add unlimited customizable “I Agree with the terms and conditions” checkboxes to the WooCommerce checkout page." +msgid "Are you looking for more advanced features to customize your WooCommerce store’s checkout process? Upgrade to Woo Additional Terms PRO and get access to a wealth of additional functionalities that will allow you to take control of your store’s policies and improve customer trust." msgstr "" -#: woo-additioanl-terms.php:313 +#: woo-additioanl-terms.php:467 msgctxt "upsell" -msgid "Display terms in a modal" +msgid "With Woo Additional Terms PRO, you’ll enjoy an abundance of features that aren’t available in the free version, including:" msgstr "" -#: woo-additioanl-terms.php:314 +#: woo-additioanl-terms.php:472 msgctxt "upsell" -msgid "(Non) Skippable checkboxes" +msgid "Unlimited custom terms and conditions checkboxes" msgstr "" -#: woo-additioanl-terms.php:315 +#: woo-additioanl-terms.php:476 msgctxt "upsell" -msgid "Unlimited T&C checkboxes" +msgid "Create complex conditional logic to display checkboxes" msgstr "" -#: woo-additioanl-terms.php:316 +#: woo-additioanl-terms.php:480 msgctxt "upsell" -msgid "Unlimited ToS page links" +msgid "Restrict terms checkboxes by Products" msgstr "" -#: woo-additioanl-terms.php:317 +#: woo-additioanl-terms.php:484 msgctxt "upsell" -msgid "Smart conditional logic" +msgid "Restrict terms checkboxes by Tags" msgstr "" -#: woo-additioanl-terms.php:318 +#: woo-additioanl-terms.php:488 msgctxt "upsell" -msgid "Detailed acceptance summary" +msgid "Restrict terms checkboxes by Categories" msgstr "" -#: woo-additioanl-terms.php:319 +#: woo-additioanl-terms.php:492 msgctxt "upsell" -msgid "Multilingual ready" +msgid "Restrict terms checkboxes by Types of products" msgstr "" -#: woo-additioanl-terms.php:320 +#: woo-additioanl-terms.php:496 msgctxt "upsell" -msgid "Easy to install" +msgid "Restrict terms checkboxes by Shipping classes" msgstr "" -#: woo-additioanl-terms.php:324 +#: woo-additioanl-terms.php:500 msgctxt "upsell" -msgid "Smart logic conditions will allow you to define restrictions based on several complex rules, such as products in the cart, which categories, tags, shipping classes, etc., cart items belong." +msgid "Restrict terms checkboxes by WooCommerce brands" msgstr "" -#. translators: 1: Open anchor tag, 2: Close anchor tag. -#: woo-additioanl-terms.php:331 +#: woo-additioanl-terms.php:504 msgctxt "upsell" -msgid "Get %s Pro and Unlock all the Powerful Features →" +msgid "Restrict terms checkboxes by Locations" msgstr "" -#: woo-additioanl-terms.php:408 +#: woo-additioanl-terms.php:508 +msgctxt "upsell" +msgid "Track of agreements with detailed acceptance summary" +msgstr "" + +#: woo-additioanl-terms.php:512 +msgctxt "upsell" +msgid "Display the terms content in a modal" +msgstr "" + +#: woo-additioanl-terms.php:516 +msgctxt "upsell" +msgid "Display the terms content in a new tab" +msgstr "" + +#: woo-additioanl-terms.php:520 +msgctxt "upsell" +msgid "Choose to make the terms checkbox required or optional" +msgstr "" + +#: woo-additioanl-terms.php:524 +msgctxt "upsell" +msgid "Choose whether or not the checkbox is checked by default" +msgstr "" + +#: woo-additioanl-terms.php:528 +msgctxt "upsell" +msgid "Import and export your plugin settings and content" +msgstr "" + +#: woo-additioanl-terms.php:532 +msgctxt "upsell" +msgid "Why settle for the basic version when you can have access to all these advanced features?" +msgstr "" + +#: woo-additioanl-terms.php:536 +msgctxt "upsell" +msgid "Go PRO for More Options" +msgstr "" + +#: woo-additioanl-terms.php:636 msgid "required" msgstr "" -#: woo-additioanl-terms.php:468 -msgid "Accepted" +#: woo-additioanl-terms.php:729 +msgid "Additional terms and conditions:" msgstr "" -#: woo-additioanl-terms.php:468 -msgid "N/A" +#: woo-additioanl-terms.php:735 +msgid "Accepted" msgstr "" #. translators: 1: Open paragraph tag, 2: Plugin name, 3: Five stars, 4: Close paragraph tag. -#: woo-additioanl-terms.php:490 -msgid "%1$sIf you like %2$s please leave us a %3$s rating to help us spread the word!%4$s" +#: woo-additioanl-terms.php:760 +msgid "%1$sIf you are happy with %2$s please leave us a %3$s rating to help us spread the word!%4$s" msgstr "" -#: woo-additioanl-terms.php:493 +#: woo-additioanl-terms.php:763 msgid "five star" msgstr "" #. translators: 1: Open anchor tag, 2: Close anchor tag. -#: woo-additioanl-terms.php:509 +#: woo-additioanl-terms.php:787 msgctxt "plugin link" msgid "%1$sGet PRO%2$s" msgstr "" #. translators: 1: Open anchor tag, 2: Close anchor tag. -#: woo-additioanl-terms.php:529 +#: woo-additioanl-terms.php:810 msgctxt "plugin link" msgid "%1$sCommunity support%2$s" msgstr "" #. translators: 1: Open anchor tag, 2: Close anchor tag. -#: woo-additioanl-terms.php:540 +#: woo-additioanl-terms.php:821 msgctxt "plugin settings page" msgid "%1$sSettings%2$s" msgstr "" #. translators: 1: Dashicon, 2: Plugin name, 3: Open anchor tag, 4: Close anchor tag. -#: woo-additioanl-terms.php:562 +#: woo-additioanl-terms.php:846 msgctxt "admin notice" msgid "%1$s Thanks for installing %2$s plugin! To get started, visit the %3$splugin’s settings page%4$s." msgstr "" -#: woo-additioanl-terms.php:587 +#: woo-additioanl-terms.php:876 msgctxt "settings section name" msgid "Terms and Conditions" msgstr "" -#: woo-additioanl-terms.php:589 +#: woo-additioanl-terms.php:877 msgctxt "settings section description" msgid "This section controls the display of your additional terms and condition fieldset." msgstr "" -#: woo-additioanl-terms.php:592 +#: woo-additioanl-terms.php:881 msgctxt "settings field name" msgid "Terms page" msgstr "" -#: woo-additioanl-terms.php:593 +#: woo-additioanl-terms.php:882 msgctxt "settings field description" msgid "If you define a \"Terms\" page the customer will be asked if they accept additional terms when checking out." msgstr "" -#: woo-additioanl-terms.php:602 +#: woo-additioanl-terms.php:891 msgctxt "settings field name" msgid "Notice content" msgstr "" -#: woo-additioanl-terms.php:603 +#: woo-additioanl-terms.php:892 msgctxt "settings field description" msgid "Text for the additional terms checkbox that customers must accept." msgstr "" -#: woo-additioanl-terms.php:604 +#. translators: %s: shortcode. +#: woo-additioanl-terms.php:894 msgctxt "settings field default value" -msgid "I have read and agree to the website [additional-terms]" +msgid "I have read and agree to the website %s" msgstr "" -#: woo-additioanl-terms.php:605 +#. translators: %s: shortcode. +#: woo-additioanl-terms.php:896 msgctxt "settings field placeholder" -msgid "I have read and agree to the website [additional-terms]" +msgid "I have read and agree to the website %s" +msgstr "" + +#. translators: 1: Open paragraph tag, 2: Shortcode, 3: Close paragraph tag. +#: woo-additioanl-terms.php:911 +msgctxt "settings field text" +msgid "%1$sInclude the %2$s shortcode in the Notice, to display the page name linked to the terms page in the checkbox label.%3$s" msgstr "" -#: woo-additioanl-terms.php:617 +#: woo-additioanl-terms.php:918 msgctxt "settings field name" msgid "Error message" msgstr "" -#: woo-additioanl-terms.php:618 +#: woo-additioanl-terms.php:919 msgctxt "settings field description" msgid "Display friendly notice whenever customer doesn’t accept additional terms." msgstr "" -#: woo-additioanl-terms.php:619 +#: woo-additioanl-terms.php:920 msgctxt "settings field default value" msgid "Please read and accept the additional terms and conditions to proceed with your order. " msgstr "" -#: woo-additioanl-terms.php:620 +#: woo-additioanl-terms.php:921 msgctxt "setting field placeholder" msgid "You must accept our additional terms." msgstr "" diff --git a/package.json b/package.json index 9bfbd91..173d34a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mypreview/woo-additional-terms", - "version": "1.5.1", + "version": "1.5.2", "private": true, "description": "Add additional terms and condition checkbox to the WooCommerce checkout.", "homepage": "https://github.com/mypreview/woo-additional-terms#readme", diff --git a/readme.txt b/readme.txt index b32a56c..906ff10 100644 --- a/readme.txt +++ b/readme.txt @@ -3,37 +3,52 @@ Contributors: mahdiyazdani, mypreview, gookaani Tags: terms and conditions, I agree, age verification, terms of service, custom terms, woocommerce plugin, GDPR, terms conditions for woocommerce Donate link: https://mypreview.one/woo-additional-terms Requires at least: 5.0 -Tested up to: 6.1 +Tested up to: 6.2 Requires PHP: 7.4 -Stable tag: 1.5.1 +Stable tag: 1.5.2 License: GPLv3 or later License URI: http://www.gnu.org/licenses/gpl-3.0.txt -Add another “I Agree with the terms and conditions” checkbox to the WooCommerce checkout page. +Improve your checkout process by adding an extra checkbox for terms and conditions. Keep track of acceptance to ensure transparency and security. == Description == -This plugin will be most helpful for e-Commerce stores in Europe as many countries in the union require the cancellation or GDPR (General Data Protection Regulation) policy to be displayed as a separate checkbox and agree by the customer before placing the order. +The Woo Additional Terms plugin is a crucial tool for any WooCommerce store as it allows you to add custom terms and conditions that customers must accept prior to checking out on your store. The additional terms and conditions checkbox serves as a valuable resource for tailoring your store’s policies, safeguarding your business, and promoting transparency with your clients. This feature enables you to provide your customers with more comprehensive details about your policies, procedures, or any additional terms that they must agree to before making a purchase. By doing so, you can cultivate a trusting relationship with your customers and minimize the likelihood of conflicts or misunderstandings. -Linking an optional page to the additional term’s notice will allow you to present customers with Additional Terms and Conditions to accept during checkout. “Terms” open up on the page when the link is clicked, and customers can review without leaving checkout. As an example, you may want to include a cancellation policy and ask customers to agree to it before placing the order. +By linking your terms page to the additional terms notice, you can grant your customers access to the terms without leaving the checkout page. As a result, the process becomes smooth and stress-free. -If the checkbox is not checked and the customer attempts to place an order, an alert box will be shown that prevents them from moving forward. +Besides, the plugin offers a user-friendly and straightforward approach to include the additional terms and conditions checkbox to your store’s checkout process, whether you are using the WooCommerce checkout shortcode or the Checkout block. In the checkout page created by shortcode, the plugin adds the additional “I agree” checkbox below the WooCommerce terms and conditions. And, if you are using the Checkout block, the checkbox can be added using the Additional Terms block, which enables you to move it to any location within the checkout block. This feature can help you streamline the checkout process and minimize any difficulties for customers. -The plugin setup is minimal and requires no knowledge of HTML or CSS. It could not be simpler. +Furthermore, the plugin saves the acceptance of the additional terms and conditions in the order details, providing you with crucial evidence in case of any disputes with customers. You can refer to the acceptance of the terms as evidence that the customer agreed to your policies and procedures before making the purchase. This can be useful for internal purposes such as auditing, analysis, and reporting. -> **BECOME A PREMIUM USER** -> -> “Additional Terms” plugin has a premium version which comes with several extra benefits: -> -> * Display terms in a modal -> * (Not) Skippable checkboxes -> * Unlimited T&C checkboxes -> * Unlimited ToS page links -> * Smart conditional logic -> * Detailed acceptance summary -> -> *Smart logic conditions will allow you to define restrictions based on several complex rules, such as products in the cart, which categories, tags, shipping classes, etc., cart items belong.* -> -> [Upgrade to premium! →](https://mypreview.one/woo-additional-terms "Woo Additional Terms (PRO)") +Moreover, this plugin effortlessly handles multilingual sites and is fully compatible with popular plugins like WPML and Polylang. With a built-in configuration file, it’s easy to translate and use for websites targeting a global audience. + +To ensure that you have covered all the necessary bases, here are some examples of additional terms that you may want to consider including in your store: + +1. **Refund Policy**: If you have a unique refund policy for your store, you may want to include additional terms that customers must agree to before making a purchase. +2. **Subscription Agreement**: If you offer subscription products or services, you may want to include additional terms related to subscriptions. This could include information about subscription renewal and cancellation policies. +3. **Product Warranties**: If you offer product warranties or guarantees, you may want to include additional terms related to these warranties. This could include information about the duration of the warranty, what is covered under the warranty, and any exclusions or limitations. +4. **Terms of Service**: If you have unique terms of service for your store, you may want to include additional terms that customers must agree to before making a purchase. This could include information about prohibited uses of your site or products, liability limitations, and dispute resolution procedures. +5. **Age Verification**: If you sell age-restricted products, such as tobacco or alcohol, you may want to include additional terms related to age verification. +6. **Intellectual Property**: If you have unique policies related to intellectual property, such as copyright or trademark infringement policies, you may want to include additional terms that customers must agree to before making a purchase. +7. **Liability Waiver**: If you have products or services that carry a risk of injury or harm, you may want to include additional terms related to liability waivers. +8. **Sales Tax**: If you are required to collect sales tax for your products, you may want to include additional terms related to this requirement. This could include information about how sales tax is calculated, which products are subject to sales tax, and any exemptions or exceptions. +9. **Privacy Policy and GDPR**: If you collect and process personal data from your customers, you are required to have a privacy policy that complies with the General Data Protection Regulation (GDPR) if you are based in the European Union or offer products or services to EU customers. You may want to include additional terms related to your privacy policy, such as information about how you collect, use, and protect personal data, as well as any rights that customers have under the GDPR. +10. **Return Policy**: If you have a return policy for your products or services, you may want to include additional terms related to this policy. This could include information about how returns are processed, any fees or penalties that may apply, and any restrictions on refunds. + +By including these additional terms, you can provide your customers with a clear understanding of your store’s policies and procedures, ultimately enhancing their shopping experience and building trust in your brand. + +## Unlock Advanced Features for Your WooCommerce Store +If you are looking for more advanced features to customize your WooCommerce store’s checkout process, [Woo Additional Terms PRO](https://mypreview.one/woo-additional-terms "Woo Additional Terms (PRO)") is the solution for you. With the Pro version, you get all the benefits of the free version, plus many additional features that allow you to take control of your store’s policies and improve customer trust. + +With the PRO version, you can enjoy an abundance of functionalities, including: + +* **Unlimited Custom Terms and Conditions Checkboxes**: With the PRO version, you can add unlimited custom terms and conditions checkboxes to your store’s checkout process. That means you can create special terms and conditions for different products or services and require customers to agree to them before purchasing. +* **Default Checked Checkbox**: You can choose whether or not the checkbox is checked by default on checkout. That allows you to set the default value of the checkbox to either checked or unchecked, depending on your preference. +* **Flexible Display Options**: You can select which action displays the entire page content after clicking on a linked terms page. You can choose to embed the content above the checkbox, open the page content in a modal, or open the linked page in a new tab. This gives you more control over how your terms and conditions are displayed to customers. +* **Required or Optional Checkbox**: You can choose whether the terms checkbox is required or optional. This allows you to make certain terms and conditions mandatory for customers to agree to before making a purchase or give customers the option to agree to them. +* **Advanced Conditional Logic**: With Woo Additional Terms PRO, you can set rules and conditions that alter terms and conditions checkboxes based on the cart and checkout details. You can create complex logic to display a terms checkbox by adding multiple conditional rules. You can restrict terms checkboxes by Products, Tags, Categories, Types of products, Shipping classes, WooCommerce brands, and Locations. This feature enables you to tailor your terms and conditions to specific products, locations, or customer group. + +Why settle for the basic version when you can have the advanced features of Woo Additional Terms Pro? [Upgrade to the PRO](https://mypreview.one/woo-additional-terms "Woo Additional Terms (PRO)") version now and take your store to the next level. == Installation == = Minimum Requirements = @@ -58,50 +73,44 @@ The manual installation method requires downloading the plugin and uploading it Automatic updates should work smoothly, but we still recommend you back up your site. == Frequently Asked Questions == -= How do I add the additional checkbox to the checkout page? = -1. Log into your WordPress website dashboard. -2. Add a new page ie. “EU Terms and Conditions” with your details. -3. Navigate to “WooCommerce” » “Settings” » “Additional Terms” tab and select the page you created in step 2. += Why should you use the Woo Additional Terms plugin? = +You may want to use the Woo Additional Terms plugin if you need to add customized terms and conditions to your online store’s checkout process. This plugin can be particularly helpful in ensuring that customers are aware of important policies, such as your return or privacy policy, that they must agree to before purchasing. By clearly communicating this information, you can enhance the user experience and increase customer satisfaction, leading to positive reviews and repeat business. -= Is this plugin compatible with WooCommerce Checkout block? = -Yes. The plugin fully supports the block-based checkout flow. You can insert the dedicated “Additional Terms” block into the “Checkout” block to display the additional T&C checkbox at your chosen location. - -= Does this plugin supports WPML? = -Yes. The plugin is translation-ready and has a config file to support both WPML and Polylang plugins fully. - -= How do I get help with the plugin? = -The easiest way to receive support is to “Create a new topic” by visiting Community Forums page [here](https://wordpress.org/support/plugin/woo-additional-terms "Woo Additional Terms Support Forum"). - -Make sure to check the “Notify me of follow-up replies via email” checkbox to receive notifications, as soon as a reply posted to your question or inquiry. += Where can I find the plugin’s settings page? = +To access the plugin’s settings page, log into your WordPress website dashboard, and navigate to “WooCommerce” » “Settings” » “Additional Terms”. -*Please note that this is an opensource 100% volunteer project, and it’s not unusual to get reply days or even weeks later.* - -= Can I help in translating this plugin into a new language? = -The plugin is fully translation-ready and localized using the GNU framework, and translators are welcome to contribute to the plugin. += How do I add the additional checkbox to the checkout page? = +To add an additional checkbox to the checkout page using the Woo Additional Terms plugin, follow these steps: +1. Navigate to “WooCommerce” » “Settings” » “Additional Terms”. +2. Select the “Terms page” where you have published the terms and conditions you want customers to agree to. +3. Enter a “Notice Content” (label) for the checkbox input field. +4. Enter an “Error message” to display if the customer tries to proceed without agreeing to the terms. +5. Click “Save Changes”. -Here’s the [WordPress translation website →](https://translate.wordpress.org/projects/wp-plugins/woo-additional-terms "WordPress translation website") += How do I add the linked page to the additional checkbox? = +You can add the linked page name to the checkbox label using the `[additional-terms]` shortcode. Insert the shortcode in the “Notice Content” field where you want the linked page name to appear. This will help your customers quickly access and review the terms and conditions by clicking the link in the checkbox. -= How do I contribute to this plugin? = -We welcome contributions in any form, and you can help reporting, testing, and detailing bugs. += Is this plugin compatible with WooCommerce Checkout block? = +Yes, the Woo Additional Terms plugin is fully compatible with the block-based checkout flow in WooCommerce. You can easily insert the dedicated “Additional Terms” block into the “Checkout” block to display the additional terms and conditions checkbox at your preferred location on the checkout page. -Here’s the [GitHub development repository →](https://github.com/mypreview/woo-additional-terms "GitHub development repository") += How can I get help with the plugin? = +The easiest way to receive support is to visit the [Community Forums page](https://wordpress.org/support/plugin/woo-additional-terms "Woo Additional Terms Support Forum") and create a new topic. Be sure to check the “Notify me of follow-up replies via email” checkbox to receive notifications as soon as a reply is posted to your question or inquiry. -= Did you like the idea behind this plugin? = -Please share your experience by leaving this plugin [5 shining stars](https://wordpress.org/support/plugin/woo-additional-terms/reviews/ "Rate Woo Additional Terms 5 stars") if you like it, thanks! += Is the plugin compatible with multilingual websites? = +Yes, absolutely. The plugin has been designed to be translation-ready and comes with a configuration file that fully supports WPML and Polylang plugins. -= Is there a premium version to upgrade? = -Yes, there is! += Can I contribute to translating the plugin into a new language? = +Yes, certainly! The plugin has been made translation-ready and localized using the GNU framework, and we welcome translators who would like to contribute to the plugin. You can visit the WordPress translation website to get started. +[Here’s the link →](https://translate.wordpress.org/projects/wp-plugins/woo-additional-terms "WordPress translation website") -Currently, the key features offered by the premium (paid) version of the plugin are: += How can I contribute to this plugin? = +We welcome contributions in various forms, such as bug reporting, testing, and providing detailed feedback. You can check out our [GitHub development repository](https://github.com/mypreview/woo-additional-terms "GitHub development repository") for more information. -* Display terms in a modal -* (Not) Skippable checkboxes -* Unlimited T&C checkboxes -* Unlimited ToS page links -* Smart conditional logic -* Detailed acceptance summary += What is your opinion about the concept behind this plugin? = +If you enjoyed using this plugin, we would greatly appreciate your feedback in the form of a [5-star rating](https://wordpress.org/support/plugin/woo-additional-terms/reviews/ "Rate Woo Additional Terms 5 stars"). Your rating will help us improve and continue providing high-quality services. Thank you! -[Go Premium, Be Happy! →](https://mypreview.one/woo-additional-terms "Woo Additional Terms (PRO)") += Does Woo Additional Terms have a pro or premium version? = +Yes, it does. The [Woo Additional Terms PRO](https://mypreview.one/woo-additional-terms "Woo Additional Terms (PRO)") is available as an upgrade and offers additional features and third-party integrations. == Screenshots == 1. Additional terms and condition checkbox on the WooCommerce checkout page. @@ -111,6 +120,10 @@ Currently, the key features offered by the premium (paid) version of the plugin 5. Additional terms and condition checkbox on the WooCommerce checkout block page. == Changelog == += 1.5.2 = +* Compatibility with WordPress 6.2 +* Compatibility with WooCommerce 7.5 + = 1.5.1 = * Update font-size for the checkout block * Compatibility with WooCommerce 7.4 diff --git a/uninstall.php b/uninstall.php index 3855057..7817dd3 100644 --- a/uninstall.php +++ b/uninstall.php @@ -1,18 +1,23 @@ init(); @@ -103,20 +131,23 @@ public static function instance() { /** * Load actions. * - * @since 1.0.0 - * @return void + * @since 1.0.0 + * + * @return void */ private function init() { + add_action( 'init', array( self::instance(), 'textdomain' ) ); add_action( 'admin_init', array( self::instance(), 'check_activation_timestamp' ) ); add_action( 'admin_notices', array( self::instance(), 'admin_notices' ) ); add_action( 'wp_ajax_woo_additional_terms_dismiss_upsell', array( self::instance(), 'dismiss_upsell' ) ); add_action( 'wp_ajax_woo_additional_terms_dismiss_rate', array( self::instance(), 'dismiss_rate' ) ); + add_action( 'wp_ajax_woo_additional_terms_dismiss_rated', array( self::instance(), 'dismiss_rated' ) ); add_action( 'before_woocommerce_init', array( self::instance(), 'add_compatibility' ) ); - add_filter( 'woocommerce_settings_tabs_array', array( self::instance(), 'add_settings_tab' ), 999, 1 ); - add_action( 'woocommerce_settings_tabs_' . WOO_ADDITIONAL_TERMS_SLUG, array( self::instance(), 'render_plugin_page' ) ); - add_action( 'woocommerce_update_options_' . WOO_ADDITIONAL_TERMS_SLUG, array( self::instance(), 'update_plugin_page' ) ); - add_action( 'woocommerce_after_settings_' . WOO_ADDITIONAL_TERMS_SLUG, array( self::instance(), 'upsell_after_settings' ) ); + add_filter( 'woocommerce_settings_tabs_array', array( self::instance(), 'add_settings_tab' ), 999 ); + add_action( 'woocommerce_settings_tabs_' . self::SLUG, array( self::instance(), 'render_plugin_page' ) ); + add_action( 'woocommerce_update_options_' . self::SLUG, array( self::instance(), 'update_plugin_page' ) ); + add_action( 'woocommerce_after_settings_' . self::SLUG, array( self::instance(), 'upsell_after_settings' ) ); add_action( 'admin_enqueue_scripts', array( self::instance(), 'admin_enqueue' ) ); add_action( 'wp_enqueue_scripts', array( self::instance(), 'enqueue' ) ); add_action( 'woocommerce_blocks_checkout_block_registration', array( self::instance(), 'checkbox_block' ) ); @@ -127,27 +158,32 @@ private function init() { add_filter( 'admin_footer_text', array( self::instance(), 'ask_to_rate' ) ); add_filter( 'plugin_action_links_' . WOO_ADDITIONAL_TERMS_PLUGIN_BASENAME, array( self::instance(), 'add_action_links' ) ); add_filter( 'plugin_row_meta', array( self::instance(), 'add_meta_links' ), 10, 2 ); - register_activation_hook( WOO_ADDITIONAL_TERMS_FILE, array( self::instance(), 'activation' ) ); - register_deactivation_hook( WOO_ADDITIONAL_TERMS_FILE, array( self::instance(), 'deactivation' ) ); + + register_activation_hook( __FILE__, array( self::instance(), 'activation' ) ); + register_deactivation_hook( __FILE__, array( self::instance(), 'deactivation' ) ); } /** * Cloning instances of this class is forbidden. * - * @since 1.0.0 - * @return void + * @since 1.0.0 + * + * @return void */ protected function __clone() { + _doing_it_wrong( __FUNCTION__, esc_html_x( 'Cloning instances of this class is forbidden.', 'clone', 'woo-additional-terms' ), esc_html( WOO_ADDITIONAL_TERMS_VERSION ) ); } /** * Unserializing instances of this class is forbidden. * - * @since 1.0.0 - * @return void + * @since 1.0.0 + * + * @return void */ public function __wakeup() { + _doing_it_wrong( __FUNCTION__, esc_html_x( 'Unserializing instances of this class is forbidden.', 'wakeup', 'woo-additional-terms' ), esc_html( WOO_ADDITIONAL_TERMS_VERSION ) ); } @@ -155,12 +191,15 @@ public function __wakeup() { * Load languages file and text domains. * Define the internationalization functionality. * - * @since 1.0.0 - * @return void + * @since 1.0.0 + * + * @return void */ public function textdomain() { + $domain = 'woo-additional-terms'; - $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound + $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . "{$domain}/{$domain}-{$locale}.mo" ); load_plugin_textdomain( $domain, false, dirname( WOO_ADDITIONAL_TERMS_PLUGIN_BASENAME ) . '/languages/' ); @@ -169,10 +208,12 @@ public function textdomain() { /** * Check date on admin initiation and add to admin notice if it was more than the time limit. * - * @since 1.4.1 - * @return void + * @since 1.4.1 + * + * @return void */ public function check_activation_timestamp() { + if ( get_transient( 'woo_additional_terms_rate' ) ) { return; } @@ -183,65 +224,159 @@ public function check_activation_timestamp() { if ( ! $activation_timestamp ) { add_site_option( $option_name, time() ); - $activation_timestamp = get_site_option( $option_name ); } } /** * Prints admin screen notices. * - * @since 1.4.0 - * @return void + * @since 1.4.0 + * + * @return void */ public function admin_notices() { + // Query WooCommerce activation. - if ( ! $this->is_woocommerce() ) { - /* translators: 1: Dashicon, Open anchor tag, 2: Close anchor tag. */ - $message = sprintf( esc_html_x( '%1$s requires the following plugin: %2$sWooCommerce%3$s', 'admin notice', 'woo-additional-terms' ), sprintf( ' %s', WOO_ADDITIONAL_TERMS_NAME ), '', '' ); - printf( '

%s

', wp_kses_post( $message ) ); - } else { - // Display a friendly admin notice upon plugin activation. - $welcome_notice_transient = 'woo_additional_terms_welcome_notice'; - $welcome_notice = get_transient( $welcome_notice_transient ); - if ( $welcome_notice ) { - printf( '

%s

', wp_kses_post( $welcome_notice ) ); - delete_transient( $welcome_notice_transient ); - } else { - if ( ! get_transient( 'woo_additional_terms_upsell' ) && ( time() - (int) get_site_option( 'woo_additional_terms_activation_timestamp' ) ) > DAY_IN_SECONDS ) { - /* translators: 1: HTML Symbol, 2: HTML symbol, 3: Open anchor tag, 4: Close anchor tag. */ - $message = sprintf( esc_html_x( '%1$s Add unlimited “I Agree with terms & conditions” checkboxes to the WooCommerce checkout without any manual effort needed. %2$s %3$sUpgrade to PRO%4$s', 'admin notice', 'woo-additional-terms' ), '☑', '→', sprintf( '', esc_url( WOO_ADDITIONAL_TERMS_URI ) ), '' ); - printf( '

%s

', esc_attr( WOO_ADDITIONAL_TERMS_SLUG ), wp_kses_post( $message ) ); - } elseif ( ! get_transient( 'woo_additional_terms_rate' ) && ( time() - (int) get_site_option( 'woo_additional_terms_activation_timestamp' ) ) > WEEK_IN_SECONDS ) { - /* translators: 1: HTML symbol, 2: Plugin name, 3: Activation duration, 4: HTML symbol, 5: Open anchor tag, 6: Close anchor tag. */ - $message = sprintf( esc_html_x( '%1$s You have been using the %2$s plugin for %3$s now, do you like it as much as we like you? %4$s %5$sRate 5-Stars%6$s', 'admin notice', 'woo-additional-terms' ), '★', esc_html( WOO_ADDITIONAL_TERMS_NAME ), human_time_diff( (int) get_site_option( 'woo_additional_terms_activation_timestamp' ), time() ), '→', sprintf( '★ ', esc_attr( WOO_ADDITIONAL_TERMS_SLUG ) ), '' ); - printf( '

%s

', esc_attr( WOO_ADDITIONAL_TERMS_SLUG ), wp_kses_post( $message ) ); - } - } - } + if ( ! $this->is_woocommerce() ) : + $message = sprintf( + /* translators: 1: Dashicon, Open anchor tag, 2: Close anchor tag. */ + esc_html_x( '%1$s requires the following plugin: %2$sWooCommerce%3$s', 'admin notice', 'woo-additional-terms' ), + sprintf( + ' %s', + WOO_ADDITIONAL_TERMS_NAME + ), + '', + '' + ); + ?> +
+

+
+ +
+

+
+ is_pro() && ! get_transient( 'woo_additional_terms_upsell' ) && ( time() - (int) get_site_option( 'woo_additional_terms_activation_timestamp' ) ) > DAY_IN_SECONDS ) : + ?> +
+

+ + + + +

+

+ +

+

+ +

+

+ + → + +

+
+ WEEK_IN_SECONDS ) : + ?> +
+

+ + + + +

+

+ +

+

+ + ★ + → + + + +

+
+ is_pro() ) { + return; + } + ?>

- +

-

- +

+ +

+

+

-
    -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • +
      +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • +
    • + + +
    -

    - - - +

    +

    -

    +

    - + + →

@@ -339,74 +544,97 @@ public function upsell_after_settings() { /** * Enqueue scripts and styles for admin pages. * - * @since 1.4.0 - * @return void + * @since 1.4.0 + * + * @return void */ public function admin_enqueue() { - wp_register_script( WOO_ADDITIONAL_TERMS_SLUG, trailingslashit( WOO_ADDITIONAL_TERMS_DIR_URL ) . 'assets/js/' . WOO_ADDITIONAL_TERMS_MIN_DIR . 'admin.js', array( 'jquery' ), WOO_ADDITIONAL_TERMS_VERSION, true ); - wp_localize_script( WOO_ADDITIONAL_TERMS_SLUG, 'watVars', array( 'dismiss_nonce' => wp_create_nonce( WOO_ADDITIONAL_TERMS_SLUG . '-dismiss' ) ) ); + + wp_register_script( self::SLUG, trailingslashit( WOO_ADDITIONAL_TERMS_DIR_URL ) . 'assets/js/' . WOO_ADDITIONAL_TERMS_MIN_DIR . 'admin.js', array( 'jquery' ), WOO_ADDITIONAL_TERMS_VERSION, true ); + wp_localize_script( self::SLUG, 'watVars', array( 'dismiss_nonce' => wp_create_nonce( self::NONCE ) ) ); if ( ! get_transient( 'woo_additional_terms_rate' ) || ! get_transient( 'woo_additional_terms_upsell' ) ) { - wp_enqueue_script( WOO_ADDITIONAL_TERMS_SLUG ); + wp_enqueue_script( self::SLUG ); } } /** * Enqueue scripts and styles. * - * @since 1.4.0 - * @return void + * @since 1.4.0 + * + * @return void */ public function enqueue() { - wp_register_style( WOO_ADDITIONAL_TERMS_SLUG, trailingslashit( WOO_ADDITIONAL_TERMS_DIR_URL ) . 'assets/css/' . WOO_ADDITIONAL_TERMS_MIN_DIR . 'style.css', null, WOO_ADDITIONAL_TERMS_VERSION, 'screen' ); - wp_register_script( WOO_ADDITIONAL_TERMS_SLUG, trailingslashit( WOO_ADDITIONAL_TERMS_DIR_URL ) . 'assets/js/' . WOO_ADDITIONAL_TERMS_MIN_DIR . 'script.js', array( 'jquery', 'wc-checkout' ), WOO_ADDITIONAL_TERMS_VERSION, true ); + + wp_register_style( self::SLUG, trailingslashit( WOO_ADDITIONAL_TERMS_DIR_URL ) . 'assets/css/' . WOO_ADDITIONAL_TERMS_MIN_DIR . 'style.css', null, WOO_ADDITIONAL_TERMS_VERSION, 'screen' ); + wp_register_script( self::SLUG, trailingslashit( WOO_ADDITIONAL_TERMS_DIR_URL ) . 'assets/js/' . WOO_ADDITIONAL_TERMS_MIN_DIR . 'script.js', array( 'jquery', 'wc-checkout' ), WOO_ADDITIONAL_TERMS_VERSION, true ); // Make sure the current screen displays plugin’s settings page. if ( $this->is_woocommerce() && self::terms_page_content() ) { - wp_enqueue_style( WOO_ADDITIONAL_TERMS_SLUG ); - wp_enqueue_script( WOO_ADDITIONAL_TERMS_SLUG ); + wp_enqueue_style( self::SLUG ); + wp_enqueue_script( self::SLUG ); } } /** * Registers block type and registers with WC Blocks Integration Interface. * - * @since 1.5.0 - * @param object $integration_registry WC Blocks integration registry. - * @return void + * @since 1.5.0 + * + * @param object $integration_registry WC Blocks integration registry. + * + * @return void */ public function checkbox_block( $integration_registry ) { + $integration_registry->register( new WAT_Checkout_Block_Integration() ); } /** * Display additional terms and condition checkbox on - * the checkout page before the submit (place order) button. + * the checkout page before to submit (place order) button. * - * @since 1.3.3 - * @return void + * @since 1.3.3 + * + * @return void */ public function print_checkbox() { - $page_id = (int) get_option( '_woo_additional_terms_page_id', null ); - $notice = (string) get_option( '_woo_additional_terms_notice' ); - // Bail out, if the page ID is not defined yet! - if ( ! isset( $page_id ) || empty( $page_id ) ) { - return; + $page_id = get_option( '_woo_additional_terms_page_id', null ); + $notice = get_option( '_woo_additional_terms_notice', '' ); + + if ( + ! empty( $page_id ) + && ! empty( $notice ) + && false !== strpos( $notice, self::SHORTCODE ) + && get_post( $page_id ) + ) { + $notice = str_replace( + self::SHORTCODE, + sprintf( + '%s', + esc_url( get_permalink( $page_id ) ), + wp_kses_post( get_the_title( $page_id ) ) + ), + $notice + ); } - if ( false !== strpos( $notice, '[additional-terms]' ) ) { - $notice = str_replace( '[additional-terms]', sprintf( '%s', esc_url( get_permalink( $page_id ) ), esc_html( get_the_title( $page_id ) ) ), $notice ); + if ( empty( $notice ) ) { + return; } ?>
- + +

+ + * +

wc_clean( get_option( '_woo_additional_terms_page_id', null ) ), + 'notice' => wc_clean( get_option( '_woo_additional_terms_notice', '' ) ), + ) + ); } /** * Display the acceptance of terms & conditions on the order edit page. * - * @since 1.3.3 - * @param object $order The current order object. - * @return void + * @since 1.3.3 + * + * @param object $order The current order object. + * + * @return void */ public function terms_acceptance( $order ) { - $page_id = (int) get_option( '_woo_additional_terms_page_id', null ); - // Bail out, if the page ID is not defined yet! - if ( ! isset( $page_id ) || empty( $page_id ) ) { + $value = $order->get_meta( '_woo_additional_terms' ); + + if ( ! boolval( $value ) || empty( $value ) ) { return; } - /* incorrect CSS class added here so it adopts styling we want */ + /* incorrect CSS class added here, so it adopts styling we want */ ?>
- get_meta( '_woo_additional_terms' ) ? esc_html__( 'Accepted', 'woo-additional-terms' ) : esc_html__( 'N/A', 'woo-additional-terms' ); - printf( '

%s:%s

', wp_kses_post( get_the_title( $page_id ) ), esc_html( $value ) ); - ?> +

+ + + + +

', sprintf( '%s', esc_html( WOO_ADDITIONAL_TERMS_NAME ) ), - '★★★★★', - '

' + '★★★★★', + '

' ); } @@ -499,11 +769,19 @@ public function ask_to_rate( $text ) { * Display additional links in plugins table page. * Filters the list of action links displayed for a specific plugin in the Plugins list table. * - * @since 1.3.5 - * @param array $links Plugin table/item action links. - * @return array + * @since 1.3.5 + * + * @param array $links Plugin table/item action links. + * + * @return array */ public function add_action_links( $links ) { + + // Bail early, in case the PRO version of the plugin is installed. + if ( $this->is_pro() ) { + return $links; + } + $plugin_links = array(); /* translators: 1: Open anchor tag, 2: Close anchor tag. */ $plugin_links[] = sprintf( esc_html_x( '%1$sGet PRO%2$s', 'plugin link', 'woo-additional-terms' ), sprintf( '✓ ', esc_url( WOO_ADDITIONAL_TERMS_URI ) ), '' ); @@ -514,25 +792,28 @@ public function add_action_links( $links ) { /** * Add additional helpful links to the plugin’s metadata. * - * @since 1.3.5 - * @param array $links An array of the plugin’s metadata. - * @param string $file Path to the plugin file relative to the plugins directory. - * @return array + * @since 1.3.5 + * + * @param array $links An array of the plugin’s metadata. + * @param string $file Path to the plugin file relative to the plugins' directory. + * + * @return array */ - public function add_meta_links( array $links, string $file ): array { + public function add_meta_links( $links, $file ) { + if ( WOO_ADDITIONAL_TERMS_PLUGIN_BASENAME !== $file ) { return $links; } $plugin_links = array(); /* translators: 1: Open anchor tag, 2: Close anchor tag. */ - $plugin_links[] = sprintf( esc_html_x( '%1$sCommunity support%2$s', 'plugin link', 'woo-additional-terms' ), sprintf( '', esc_html( WOO_ADDITIONAL_TERMS_SLUG ) ), '' ); + $plugin_links[] = sprintf( esc_html_x( '%1$sCommunity support%2$s', 'plugin link', 'woo-additional-terms' ), sprintf( '', esc_html( self::SLUG ) ), '' ); if ( $this->is_woocommerce() ) { $settings_url = add_query_arg( array( 'page' => 'wc-settings', - 'tab' => WOO_ADDITIONAL_TERMS_SLUG, + 'tab' => self::SLUG, ), admin_url( 'admin.php' ) ); @@ -546,10 +827,12 @@ public function add_meta_links( array $links, string $file ): array { /** * Set the activation hook for a plugin. * - * @since 1.3.4 - * @return void + * @since 1.3.4 + * + * @return void */ public function activation() { + // Set up the admin notice to be displayed on activation. $settings_url = add_query_arg( array( @@ -558,18 +841,22 @@ public function activation() { ), admin_url( 'admin.php' ) ); + /* translators: 1: Dashicon, 2: Plugin name, 3: Open anchor tag, 4: Close anchor tag. */ $welcome_notice = sprintf( esc_html_x( '%1$s Thanks for installing %2$s plugin! To get started, visit the %3$splugin’s settings page%4$s.', 'admin notice', 'woo-additional-terms' ), '', sprintf( '%s', WOO_ADDITIONAL_TERMS_NAME ), sprintf( '', esc_url( $settings_url ) ), '' ); + set_transient( 'woo_additional_terms_welcome_notice', $welcome_notice, MINUTE_IN_SECONDS ); } /** * Set the deactivation hook for a plugin. * - * @since 1.4.0 - * @return void + * @since 1.4.0 + * + * @return void */ public function deactivation() { + delete_transient( 'woo_additional_terms_rate' ); delete_transient( 'woo_additional_terms_upsell' ); delete_transient( 'woo_additional_terms_welcome_notice' ); @@ -578,15 +865,17 @@ public function deactivation() { /** * Get all the settings for this plugin. * - * @since 1.3.3 - * @return array + * @since 1.3.3 + * + * @return array */ private static function get_settings() { + $settings = array( 'section_title' => array( 'name' => esc_html_x( 'Terms and Conditions', 'settings section name', 'woo-additional-terms' ), - 'type' => 'title', 'desc' => esc_html_x( 'This section controls the display of your additional terms and condition fieldset.', 'settings section description', 'woo-additional-terms' ), + 'type' => 'title', ), 'page_id' => array( 'name' => esc_html_x( 'Terms page', 'settings field name', 'woo-additional-terms' ), @@ -601,35 +890,50 @@ private static function get_settings() { 'notice' => array( 'name' => esc_html_x( 'Notice content', 'settings field name', 'woo-additional-terms' ), 'desc' => esc_html_x( 'Text for the additional terms checkbox that customers must accept.', 'settings field description', 'woo-additional-terms' ), - 'default' => esc_html_x( 'I have read and agree to the website [additional-terms]', 'settings field default value', 'woo-additional-terms' ), - 'placeholder' => esc_html_x( 'I have read and agree to the website [additional-terms]', 'settings field placeholder', 'woo-additional-terms' ), + /* translators: %s: shortcode. */ + 'default' => sprintf( esc_html_x( 'I have read and agree to the website %s', 'settings field default value', 'woo-additional-terms' ), esc_html( self::SHORTCODE ) ), + /* translators: %s: shortcode. */ + 'placeholder' => sprintf( esc_html_x( 'I have read and agree to the website %s', 'settings field placeholder', 'woo-additional-terms' ), esc_html( self::SHORTCODE ) ), 'type' => 'textarea', 'css' => 'min-width:300px;', 'id' => '_woo_additional_terms_notice', 'desc_tip' => true, 'autoload' => false, 'custom_attributes' => array( - 'rows' => '4', - 'cols' => '50', + 'rows' => '4', + 'cols' => '50', + ), + ), + 'notice_info' => array( + 'type' => 'info', + 'text' => sprintf( + /* translators: 1: Open paragraph tag, 2: Shortcode, 3: Close paragraph tag. */ + esc_html_x( '%1$sInclude the %2$s shortcode in the Notice, to display the page name linked to the terms page in the checkbox label.%3$s', 'settings field text', 'woo-additional-terms' ), + '

', + '[additional-terms]', + '

', ), ), 'error' => array( - 'name' => esc_html_x( 'Error message', 'settings field name', 'woo-additional-terms' ), - 'desc' => esc_html_x( 'Display friendly notice whenever customer doesn’t accept additional terms.', 'settings field description', 'woo-additional-terms' ), - 'default' => esc_html_x( 'Please read and accept the additional terms and conditions to proceed with your order. ', 'settings field default value', 'woo-additional-terms' ), - 'placeholder' => esc_html_x( 'You must accept our additional terms.', 'setting field placeholder', 'woo-additional-terms' ), - 'type' => 'text', - 'css' => 'min-width:300px;', - 'id' => '_woo_additional_terms_error', - 'desc_tip' => true, - 'autoload' => false, + 'name' => esc_html_x( 'Error message', 'settings field name', 'woo-additional-terms' ), + 'desc' => esc_html_x( 'Display friendly notice whenever customer doesn’t accept additional terms.', 'settings field description', 'woo-additional-terms' ), + 'default' => esc_html_x( 'Please read and accept the additional terms and conditions to proceed with your order. ', 'settings field default value', 'woo-additional-terms' ), + 'placeholder' => esc_html_x( 'You must accept our additional terms.', 'setting field placeholder', 'woo-additional-terms' ), + 'type' => 'text', + 'css' => 'min-width:300px;', + 'id' => '_woo_additional_terms_error', + 'desc_tip' => true, + 'autoload' => false, + 'custom_attributes' => array( + 'required' => true, + ), ), 'section_end' => array( 'type' => 'sectionend', ), ); - return (array) apply_filters( 'woo_additional_terms_settings_args', $settings ); + return apply_filters( 'woo_additional_terms_settings_args', $settings ); } /** @@ -637,12 +941,15 @@ private static function get_settings() { * The page can be set from the plugin settings page. * “WooCommerce” » “Settings” » “Additional Terms” * - * @since 1.3.3 - * @param int $terms_page_id Additional terms page ID. - * @param bool $echo Output additional terms page content on the page. - * @return void|bool + * @since 1.3.3 + * + * @param int $terms_page_id Additional terms page ID. + * @param bool $echo Output additional terms page content on the page. + * + * @return void|bool */ public static function terms_page_content( $terms_page_id = null, $echo = false ) { + $terms_page_id = $terms_page_id ? intval( $terms_page_id ) : get_option( '_woo_additional_terms_page_id', null ); // Bail early, in case the page ID is not available or not a number. @@ -666,14 +973,29 @@ public static function terms_page_content( $terms_page_id = null, $echo = false return false; } + /** + * Determine whether the pro version is active. + * + * @since 1.5.2 + * + * @return bool + */ + private function is_pro() { + + return class_exists( 'WATPRO', false ) && defined( 'WATPRO_META' ); + } + /** * Query WooCommerce activation * - * @since 1.0.0 - * @return bool + * @since 1.0.0 + * + * @return bool + * * @phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound */ private function is_woocommerce() { + // This statement prevents from producing fatal errors, // in case the WooCommerce plugin is not activated on the site. $woocommerce_plugin = apply_filters( 'woo_additional_terms_woocommerce_path', 'woocommerce/woocommerce.php' ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.HookCommentWrongStyle @@ -704,10 +1026,12 @@ private function is_woocommerce() { * then kicking off the plugin from this point in the file does * not affect the page life cycle. * - * @since 1.0.0 - * @return null|Woo_Additional_Terms The one true Woo_Additional_Terms Instance. + * @since 1.0.0 + * + * @return null|Woo_Additional_Terms The one true Woo_Additional_Terms Instance. */ function woo_additional_terms_init() { + return Woo_Additional_Terms::instance(); }