Plugin Directory

Changeset 3000911


Ignore:
Timestamp:
11/23/2023 11:53:16 PM (2 years ago)
Author:
djanym
Message:

adds woocommerce support

Location:
optional-email/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • optional-email/trunk/optional-email.php

    r2914887 r3000911  
    33Plugin Name: Optional Email
    44Description: Makes email optional field for registration
    5 Version: 1.3.7
     5Version: 1.3.9
    66Author: Nael Concescu
    77Author URI: https://cv.nael.pro/
    88Plugin URI: https://cv.nael.pro/
    99*/
     10
     11require_once plugin_dir_path( __FILE__ ) . 'inc/woocommerce.php';
    1012
    1113/**
     
    186188    ?>
    187189    <script type="text/javascript">
    188         jQuery('#reg_passmail').hide();
    189         let text = jQuery('label[for=user_email]').html();
    190         if (text && text.length) {
    191             if (text.includes("<?php _e( 'Email&nbsp;Address:', 'default' ) ?>")) {
    192                 text = text.replace("<?php _e( 'Email&nbsp;Address:', 'default' ) ?>", "<?php echo __( 'Email Address: (optional)', 'optional-email' ) ?>");
    193             } else if (text.includes("<?php _e( 'Email Address:', 'default' ) ?>")) {
    194                 text = text.replace("<?php _e( 'Email Address:', 'default' ) ?>", "<?php echo __( 'Email Address: (optional)', 'optional-email' ) ?>");
    195             } else {
    196                 text = text.replace("<?php _e( 'Email', 'default' ) ?>", "<?php echo __( 'Email (optional)', 'optional-email' ) ?>");
    197                 text = text.replace("<?php _e( 'E-mail', 'default' ) ?>", "<?php echo __( 'E-mail (optional)', 'optional-email' ) ?>");
     190        jQuery(document).ready(function ($) {
     191            $('#reg_passmail').hide();
     192            let email_fld = $('label[for=user_email], label[for=reg_email]');
     193            let text = email_fld.html();
     194
     195            // Define an array of search and replace pairs.
     196            let replacements = [
     197                {search: '<?php echo esc_html( __( 'Email&nbsp;Address:', 'default' ) ); ?>', replace: '<?php echo esc_html( __( 'Email Address: (optional)', 'optional-email' ) ); ?>'},
     198                {search: '<?php echo esc_html( __( 'Email Address:', 'default' ) ); ?>', replace: '<?php echo esc_html( __( 'Email Address: (optional)', 'optional-email' ) ); ?>'},
     199                {search: '<?php echo esc_html( __( 'Email address', 'woocommerce' ) ); ?>', replace: '<?php echo esc_html( __( 'Email Address (optional)', 'optional-email' ) ); ?>'},
     200                {search: '<?php echo esc_html( __( 'Email', 'default' ) ); ?>', replace: '<?php echo esc_html( __( 'Email (optional)', 'optional-email' ) ); ?>'},
     201                {search: '<?php echo esc_html( __( 'E-mail', 'default' ) ); ?>', replace: '<?php echo esc_html( __( 'E-mail (optional)', 'optional-email' ) ); ?>'}
     202            ];
     203
     204            if (text && text.length) {
     205                // Iterate through the array and perform replacements
     206                for (let i = 0; i < replacements.length; i++) {
     207                    let pattern = new RegExp(replacements[i].search, 'gi');
     208
     209                    // Check if there are matches
     210                    if (text.match(pattern)) {
     211                        // Make the replacement
     212                        text = text.replace(pattern, replacements[i].replace);
     213                        // Break out of the loop since a replacement has been made
     214                        break;
     215                    }
     216                }
     217
     218                // Replace email field text with the new optional.
     219                email_fld.html(text);
    198220            }
    199             jQuery('label[for=user_email]').html(text);
    200         }
    201 
    202         // Another text to replace
    203         text = jQuery('#setupform').html();
    204         if (text && text.length) {
    205             text = text.replace("<?php esc_attr_e( 'We send your registration email to this address. (Double-check your email address before continuing.)', 'default' ) ?>", '');
    206             jQuery('#setupform').html(text);
    207         }
     221
     222            // Another text to replace
     223            text = jQuery('#setupform').html();
     224            if (text && text.length) {
     225                text = text.replace("<?php esc_attr_e( 'We send your registration email to this address. (Double-check your email address before continuing.)', 'default' ) ?>", '');
     226                jQuery('#setupform').html(text);
     227            }
     228        });
    208229    </script>
    209230    <?php
    210231}
    211 // For register page
    212 add_action( 'login_footer', 'oe_login_footer', 1 );
    213 // For MU signup page
    214 add_action( 'after_signup_form', 'oe_login_footer', 1 );
     232add_action( 'login_footer', 'oe_login_footer', 1 ); // For register page.
     233add_action( 'after_signup_form', 'oe_login_footer', 1 ); // For MU signup page.
     234add_action( 'woocommerce_register_form_end', 'oe_login_footer', 1 ); // Runs at the end of the WooCommerce register form.
    215235
    216236function oe_login_scripts() {
  • optional-email/trunk/readme.txt

    r2914887 r3000911  
    33Tags: email field, registration email, profile email, password registration
    44Requires at least: 4.6
    5 Tested up to: 6.3
    6 Stable tag: 1.3.7
     5Tested up to: 6.9
     6Stable tag: 1.3.9
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1616Also will add a password field on the registration page.
    1717Supports multisite.
     18Supports WooCommerce.
    1819
    1920Plugin support [Optional Email Plugin](https://cv.nael.pro/ "Optional Email Plugin")
     
    29301. Registration form
    30312. Profile form
     323. WooCommerce registration form
     334. WooCommerce edit account form
    3134
    3235== Changelog ==
    3336 
     37= 1.3.9 =
     38* Added support for the WooCommerce.
     39* Tested with WordPress version 6.9
     40
    3441= 1.3.7 =
    3542* Tested with WordPress version 6.2
Note: See TracChangeset for help on using the changeset viewer.