Plugin Directory

Changeset 3144677


Ignore:
Timestamp:
08/31/2024 12:48:56 PM (19 months ago)
Author:
wphex
Message:

"new version"

Location:
hex-coupon-for-woocommerce
Files:
683 added
27 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • hex-coupon-for-woocommerce/trunk/Readme.txt

    r3142968 r3144677  
    11=== HexCoupon - Advanced Tools for WooCommerce Coupons, BOGO, Store Credit, Loyalty Programs, and More ===
    22Contributors: wphex, palashwpdev
    3 Donate link: https://example.com/
    4 Tags: bogo, buy one get one, store credit, loyalty program, woocommerce coupon
     3Tags: bogo, store credit, loyalty program, spin wheel, woocommerce coupon
    54Requires PHP: 7.1
    65Requires at least: 5.4
    76Tested up to: 6.6.1
    8 Version: 1.2.3
    9 Stable tag: 1.2.3
     7Version: 1.2.4
     8Stable tag: 1.2.4
    109License: GPLv2 or later
    1110License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    166165
    167166== Changelog ==
     167== 1.2.4 ==
     168Made some design changes.
     169
    168170== 1.2.3 ==
    169171Added new feature 'Spin Wheel'. It will be used to give a coupon after succesful spin wheel win.
     
    182184Fixed upgrade to pro notice in BOGO coupon type.
    183185
    184 == 1.1.8 ==
    185 Fixed some bugs.
    186 
    187186== Upgrade Notice ==
    188187
  • hex-coupon-for-woocommerce/trunk/app/Controllers/AjaxApiController.php

    r3142966 r3144677  
    276276        }
    277277
     278        // get all the products of WooCommerce product
    278279        $all_products = GeneralFunctionsHelpers::getInstance()->show_all_products();
     280        // get all the categories of WooCommerce product
    279281        $all_categories = GeneralFunctionsHelpers::getInstance()->show_all_categories();
     282        // get all the pages of WordPress
    280283        $all_pages = GeneralFunctionsHelpers::getInstance()->show_all_pages();
    281284
  • hex-coupon-for-woocommerce/trunk/app/Controllers/Api/SpinWheelSettingsApiController.php

    r3142966 r3144677  
    6565        add_action( 'wp_ajax_update_spin_count', [ $this, 'update_spin_count' ] );
    6666        add_action( 'wp_ajax_nopriv_update_spin_count', [ $this, 'update_spin_count' ] );
    67         // add_action( 'wp_ajax_nopriv_send_win_email', [ $this, 'send_win_email' ] );
    6867    }
    6968
     
    478477        return $html;
    479478    }
    480    
    481 
    482     /**
    483      * @package hexcoupon
    484      * @author WpHex
    485      * @since 1.0.0
    486      * @method send_win_email
    487      * @return void
    488      * Sending success message to the users for spin wheel win
    489      */
    490     public function send_win_email() {
    491         // Verify the AJAX request
    492         if ( isset( $_POST['userEmail'] ) && isset( $_POST['emailText'] ) && isset( $_POST['emailSubject'] ) ) {
    493             // Get the prize information
    494             $userEmail = sanitize_text_field( $_POST['userEmail'] );
    495             $emailSubject = sanitize_text_field( $_POST['emailSubject'] );
    496             $emailText = sanitize_text_field( $_POST['emailText'] );
    497             $coupon_code = 'testcoupon';
    498    
    499             // Set the email parameters
    500             $to = $userEmail;
    501             $subject = $emailSubject;
    502             $message = $this->email_template( $emailText, $coupon_code );
    503             $headers = [ 'Content-Type: text/html; charset=UTF-8' ];
    504    
    505             // Send the email
    506             $mail_sent = wp_mail( $to, $subject, $message, $headers );
    507    
    508             // Return a JSON response
    509             if ( $mail_sent ) {
    510                 wp_send_json_success();
    511             } else {
    512                 wp_send_json_error();
    513             }
    514 
    515         } else {
    516             wp_send_json_error( 'No prize information provided.' );
    517         }
    518     }
    519479
    520480    /**
     
    546506
    547507        // Define the coupon details
    548         $coupon_code = 'SpinWheel' . get_current_user_id() . time(); // Unique code of coupon
     508        $code = $this->get_last_created_coupon_by_email( $user_email );
     509        $last_code = $code->post_title;
     510        $get_code_number_part = explode( 'l', $last_code );
     511        $final_code = 'SpinWheel' . get_current_user_id() . $get_code_number_part[1] + 1;
    549512        $discount_amount = $value; // The discount amount
    550513       
    551514        // Check if a coupon with the same code already exists
    552         if ( ! wc_get_coupon_id_by_code( $coupon_code ) ) {
     515        if ( ! wc_get_coupon_id_by_code( $final_code ) ) {
    553516            // Create a new coupon
    554517            $coupon = new \WC_Coupon();
    555             $coupon->set_code( $coupon_code );
     518            $coupon->set_code( $final_code );
    556519            $coupon->set_amount( $discount_amount );
    557520            $coupon->set_discount_type( $discount_type );
  • hex-coupon-for-woocommerce/trunk/app/Core/AssetsManager.php

    r3142966 r3144677  
    355355
    356356        if (
    357             $enable_spin_wheel && is_home() && $show_on_homepage == 1 && $spin_count < $spin_per_email ||
    358             $enable_spin_wheel && is_blog() && $show_on_blogpage == 1 && $spin_count < $spin_per_email ||
    359             $enable_spin_wheel && is_shop() && $show_on_shoppage == 1 && $spin_count < $spin_per_email ||
    360             $enable_spin_wheel && is_single( $selected_pages ) || is_page( $selected_pages ) && $spin_count < $spin_per_email
     357                $enable_spin_wheel && is_home() && $show_on_homepage == 1 && $spin_count < $spin_per_email ||
     358                $enable_spin_wheel && is_blog() && $show_on_blogpage == 1 && $spin_count < $spin_per_email ||
     359                $enable_spin_wheel && is_shop() && $show_on_shoppage == 1 && $spin_count < $spin_per_email ||
     360                $enable_spin_wheel && is_single( $selected_pages ) || is_page( $selected_pages ) && $spin_count < $spin_per_email
    361361            ) :
    362362
     
    485485                background: {$button_bg} !important;
    486486            }
    487             .spinToWin .slice:nth-child(4n + 1 ) {
     487            .spinToWin .slice:nth-child(1),
     488            .spinToWin .slice:nth-child(3),
     489            .spinToWin .slice:nth-child(5),
     490            .spinToWin .slice:nth-child(7),
     491            .spinToWin .slice:nth-child(9),
     492            .spinToWin .slice:nth-child(11) {
    488493                --bg: {$content1_color};
    489494            }
    490             .spinToWin .slice:nth-child(4n + 2 ) {
     495            .spinToWin .slice:nth-child(2),
     496            .spinToWin .slice:nth-child(8),
     497            .spinToWin .slice:nth-child(12) {
    491498                --bg: {$content2_color};
    492499            }
    493             .spinToWin .slice:nth-child(4n + 3 ) {
     500            .spinToWin .slice:nth-child(4),
     501            .spinToWin .slice:nth-child(10) {
    494502                --bg: {$content3_color};
    495503            }
    496             .spinToWin  .slice:nth-child(4n + 4 ) {
     504            .spinToWin  .slice:nth-child(6) {
    497505                --bg: {$content4_color};
    498506            }
  • hex-coupon-for-woocommerce/trunk/app/Core/Helpers/GeneralFunctionsHelpers.php

    r3142966 r3144677  
    6363     * @author WpHex
    6464     * @since 1.0.0
    65      * @method show_all_categories
     65     * @method show_all_pages
    6666     * @return array
    6767     * Retrieve all available Pages of WP.
  • hex-coupon-for-woocommerce/trunk/app/Core/WooCommerce/SpinWheel/SpinWheel.php

    r3142966 r3144677  
    129129                                        ?>
    130130                                        <div class="slice" style="--i: 1">
    131                                             <p class="value text bankrupt" data-value="<?php echo esc_attr( $value1 ); ?>" data-label="<?php echo esc_attr( $label1 ); ?>">
     131                                            <p class="value" data-value="<?php echo esc_attr( $value1 ); ?>" data-label="<?php echo esc_attr( $label1 ); ?>">
    132132                                                <?php printf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $coupon_type1 ) ); ?>
    133133                                            </p>
     
    139139                                        </div>
    140140                                        <div class="slice" style="--i: 3">
     141                                            <p class="value" data-value="<?php echo esc_attr( $value1 ); ?>" data-label="<?php echo esc_attr( $label1 ); ?>">
     142                                                <?php printf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $coupon_type1 ) ); ?>
     143                                            </p>
     144                                        </div>
     145                                        <div class="slice" style="--i: 4">
    141146                                            <p class="value" data-value="<?php echo esc_attr( $value3 ); ?>" data-label="<?php echo esc_attr( $label3 ); ?>">
    142147                                                <?php printf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $coupon_type3 ) ); ?>
    143148                                            </p>
    144149                                        </div>
    145                                         <div class="slice" style="--i: 4">
     150                                        <div class="slice" style="--i: 5">
     151                                            <p class="value" data-value="<?php echo esc_attr( $value1 ); ?>" data-label="<?php echo esc_attr( $label1 ); ?>">
     152                                                <?php printf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $coupon_type1 ) ); ?>
     153                                            </p>
     154                                        </div>
     155                                        <div class="slice" style="--i: 6">
    146156                                            <p class="value" data-value="<?php echo esc_attr( $value4 ); ?>" data-label="<?php echo esc_attr( $label4 ); ?>">
    147157                                                <?php printf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $coupon_type4 ) ); ?>
    148158                                            </p>
    149159                                        </div>
    150                                         <div class="slice" style="--i: 5">
    151                                             <p class="value" data-value="<?php echo esc_attr( $value1 ); ?>" data-label="<?php echo esc_attr( $label1 ); ?>">
    152                                                 <?php printf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $coupon_type1 ) ); ?>
    153                                             </p>
    154                                         </div>
    155                                         <div class="slice" style="--i: 6">
     160                                        <div class="slice" style="--i: 7">
     161                                            <p class="value" data-value="<?php echo esc_attr( $value1 ); ?>" data-label="<?php echo esc_attr( $label1 ); ?>">
     162                                                <?php printf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $coupon_type1 ) ); ?>
     163                                            </p>
     164                                        </div>
     165                                        <div class="slice" style="--i: 8">
    156166                                            <p class="value" data-value="<?php echo esc_attr( $value2 ); ?>" data-label="<?php echo esc_attr( $label2 ); ?>">
    157167                                                <?php printf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $coupon_type2 ) ); ?>
    158168                                            </p>
    159169                                        </div>
    160                                         <div class="slice" style="--i: 7">
     170                                        <div class="slice" style="--i: 9">
     171                                            <p class="value" data-value="<?php echo esc_attr( $value1 ); ?>" data-label="<?php echo esc_attr( $label1 ); ?>">
     172                                                <?php printf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $coupon_type1 ) ); ?>
     173                                            </p>
     174                                        </div>
     175                                        <div class="slice" style="--i: 10">
    161176                                            <p class="value" data-value="<?php echo esc_attr( $value3 ); ?>" data-label="<?php echo esc_attr( $label3 ); ?>">
    162177                                                <?php printf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $coupon_type3 ) ); ?>
    163178                                            </p>
    164179                                        </div>
    165                                         <div class="slice" style="--i: 8">
    166                                             <p class="value" data-value="<?php echo esc_attr( $value4 ); ?>" data-label="<?php echo esc_attr( $label4 ); ?>">
    167                                                 <?php printf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $coupon_type4 ) ); ?>
    168                                             </p>
    169                                         </div>
    170                                         <div class="slice" style="--i: 9">
    171                                             <p class="value text lose-turn" data-value="<?php echo esc_attr( $value1 ); ?>" data-label="<?php echo esc_attr( $label1 ); ?>">
    172                                                 <?php printf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $coupon_type1 ) ); ?>
    173                                             </p>
    174                                         </div>
    175                                         <div class="slice" style="--i: 10">
     180                                        <div class="slice" style="--i: 11">
     181                                            <p class="value" data-value="<?php echo esc_attr( $value1 ); ?>" data-label="<?php echo esc_attr( $label1 ); ?>">
     182                                                <?php printf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $coupon_type1 ) ); ?>
     183                                            </p>
     184                                        </div>
     185                                        <div class="slice" style="--i: 12">
    176186                                            <p class="value" data-value="<?php echo esc_attr( $value2 ); ?>" data-label="<?php echo esc_attr( $label2 ); ?>">
    177187                                                <?php printf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $coupon_type2 ) ); ?>
    178188                                            </p>
    179                                         </div>
    180                                         <div class="slice" style="--i: 11">
    181                                             <p class="value" data-value="<?php echo esc_attr( $value3 ); ?>" data-label="<?php echo esc_attr( $label3 ); ?>">
    182                                                 <?php printf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $coupon_type3 ) ); ?>
    183                                             </p>
    184                                         </div>
    185                                         <div class="slice" style="--i: 12">
    186                                             <p class="value" data-value="<?php echo esc_attr( $value4 ); ?>" data-label="<?php echo esc_attr( $label4 ); ?>">
    187                                                 <?php printf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $coupon_type4 ) ); ?>
    188                                             </p>
    189                                         </div>
     189                                        </div>                                       
    190190                                    </div>
    191191                                    <div class="svg">
  • hex-coupon-for-woocommerce/trunk/assets/dev/public/css/spin.css

    r3142966 r3144677  
    191191}
    192192
    193 .spinToWin .slice:nth-child(4n + 1) {
     193.spinToWin .slice:nth-child(1) {
    194194  --bg: #E53935;
    195195}
  • hex-coupon-for-woocommerce/trunk/assets/dev/public/js/spin.js

    r3142966 r3144677  
    7474                    setTimeout(function() {
    7575                        if (innerTexts[offernum] == "NON") {
    76                             // alert(messageIfLoss + "\n" + "Discount Type: " + innerTexts[offernum] + "\n" + "Discount Details: " + innerLabel[offernum]);
    7776                            alert(messageIfLoss + "\n" + "Discount Details: " + innerLabel[offernum]);
     77                           
     78                            // Re-enable the button after the dynamic delay time
     79                            setTimeout(function() {
     80                                pointer_btn.disabled = false;
     81                                pointer_btn.style.cursor = "pointer";
     82                            }, delayTime); // Use the dynamic delay time here
     83
    7884                            return;
    7985                        } else {
    80                             // alert(messageIfWin + "\n" + "Discount Type: " + innerTexts[offernum] + "\n" + "Discount Details:" + innerLabel[offernum]);
    8186                            alert(messageIfWin + "\n" + "Discount Details: " + innerLabel[offernum]);
    8287                        }
  • hex-coupon-for-woocommerce/trunk/assets/dist/public/js/spin.min.js

    r3142966 r3144677  
    1 !function(e){"use strict";e(document).ready(function(){let t=document.querySelectorAll(".wheel .slice"),l=document.querySelector(".try-your-luck"),n=document.querySelector(".wheel"),u=0,o=spinToWinData.spinPerEmail,r=1e3*spinToWinData.delayBetweenSpin,i=1e3*spinToWinData.popupIntervalTime,a=spinToWinData.frontendMessageIfWin;spinToWinData.emailSubject,spinToWinData.emailContent;let s=spinToWinData.frontendMessageIfLoss;if(l){let c=document.querySelectorAll(".wheel .slice .value"),d=[],f=[],p=[];c.forEach(e=>{let t=e.innerText,l=e.getAttribute("data-value"),n=e.getAttribute("data-label");d.unshift(t),f.unshift(l),p.unshift(n)}),l.addEventListener("click",function(){let i=document.querySelector(".custom-input.name"),c=document.querySelector(".custom-input.email"),m=document.querySelector("#termCondition");if(i){var y=document.querySelector(".custom-input.name").value;if(!y){alert("You must fill up the name field.");return}}if(c){var h=document.querySelector(".custom-input.email").value;if(!h){alert("You must fill up the email field.");return}}if(!m.checked){alert("You must agree with the terms and conditions.");return}if(u<o){l.disabled=!0,l.style.cursor="not-allowed";let S=360/t.length,g=Math.floor(49*Math.random())*S;n.style.rotate=g+"deg";let $=g%360/S-1;setTimeout(function(){if("NON"==d[$]){alert(s+"\nDiscount Details: "+p[$]);return}alert(a+"\nDiscount Details: "+p[$]);let t={action:"update_spin_count",couponValue:f[$],couponType:d[$]};y&&(t.userName=y),h&&(t.userEmail=h),e.ajax({url:spinToWinData.ajax_url,type:"POST",data:t,success:function(e){if(e.success){let t=e.data;console.log("Spin count successfully updated to: "+t)}else e.data&&e.data.message?alert(e.data.message):console.log("Failed to update spin count.")},error:function(){console.log("An error occurred while updating the spin count.")}}),++u<o?(console.log(o),setTimeout(function(){l.disabled=!1,l.style.cursor="pointer"},r)):(alert("You have reached the maximum number of spins!"),l.style.cursor="not-allowed")},4e3)}else alert("You have already used all your spins!")})}else console.error("The 'TRY YOUR LUCK' button was not found.");let m=document.querySelector(".spinToWin .close");m?m.addEventListener("click",function(){let e=document.querySelector(".spinToWin");e&&(e.style.display="none",setTimeout(function(){e.style.display="block"},i))}):console.error("The 'CLOSE' button was not found.")})}(jQuery);
     1!function(e){"use strict";e(document).ready(function(){let t=document.querySelectorAll(".wheel .slice"),l=document.querySelector(".try-your-luck"),n=document.querySelector(".wheel"),u=0,o=spinToWinData.spinPerEmail,r=1e3*spinToWinData.delayBetweenSpin,i=1e3*spinToWinData.popupIntervalTime,s=spinToWinData.frontendMessageIfWin;spinToWinData.emailSubject,spinToWinData.emailContent;let a=spinToWinData.frontendMessageIfLoss;if(l){let c=document.querySelectorAll(".wheel .slice .value"),d=[],f=[],p=[];c.forEach(e=>{let t=e.innerText,l=e.getAttribute("data-value"),n=e.getAttribute("data-label");d.unshift(t),f.unshift(l),p.unshift(n)}),l.addEventListener("click",function(){let i=document.querySelector(".custom-input.name"),c=document.querySelector(".custom-input.email"),y=document.querySelector("#termCondition");if(i){var m=document.querySelector(".custom-input.name").value;if(!m){alert("You must fill up the name field.");return}}if(c){var h=document.querySelector(".custom-input.email").value;if(!h){alert("You must fill up the email field.");return}}if(!y.checked){alert("You must agree with the terms and conditions.");return}if(u<o){l.disabled=!0,l.style.cursor="not-allowed";let S=360/t.length,g=Math.floor(49*Math.random())*S;n.style.rotate=g+"deg";let $=g%360/S-1;setTimeout(function(){if("NON"==d[$]){alert(a+"\nDiscount Details: "+p[$]),setTimeout(function(){l.disabled=!1,l.style.cursor="pointer"},r);return}alert(s+"\nDiscount Details: "+p[$]);let t={action:"update_spin_count",couponValue:f[$],couponType:d[$]};m&&(t.userName=m),h&&(t.userEmail=h),e.ajax({url:spinToWinData.ajax_url,type:"POST",data:t,success:function(e){if(e.success){let t=e.data;console.log("Spin count successfully updated to: "+t)}else e.data&&e.data.message?alert(e.data.message):console.log("Failed to update spin count.")},error:function(){console.log("An error occurred while updating the spin count.")}}),++u<o?(console.log(o),setTimeout(function(){l.disabled=!1,l.style.cursor="pointer"},r)):(alert("You have reached the maximum number of spins!"),l.style.cursor="not-allowed")},4e3)}else alert("You have already used all your spins!")})}else console.error("The 'TRY YOUR LUCK' button was not found.");let y=document.querySelector(".spinToWin .close");y?y.addEventListener("click",function(){let e=document.querySelector(".spinToWin");e&&(e.style.display="none",setTimeout(function(){e.style.display="block"},i))}):console.error("The 'CLOSE' button was not found.")})}(jQuery);
  • hex-coupon-for-woocommerce/trunk/configs/config.php

    r3142966 r3144677  
    1010    'plugin_slug'       => 'hexcoupon',
    1111    'namespace_root'    => 'HexCoupon',
    12     'plugin_version'    => '1.2.3',
     12    'plugin_version'    => '1.2.4',
    1313    'plugin_name'       => 'HexCoupon',
    1414    'dev_mode'          => false,
  • hex-coupon-for-woocommerce/trunk/hex-coupon-for-woocommerce.php

    r3142968 r3144677  
    66 * Plugin URI: https://wordpress.org/plugins/hex-coupon-for-woocommerce
    77 * Description: Extend coupon functionality in your Woocommerce store.
    8  * Version: 1.2.3
     8 * Version: 1.2.4
    99 * Author: WpHex
    1010 * Requires at least: 5.4
     
    1212 * Requires PHP: 7.1
    1313 * WC requires at least: 6.0
    14  * WC tested up to: 9.2.2
     14 * WC tested up to: 9.2.3
    1515 * Author URI: https://wphex.com/
    1616 * License: GPLv2 or later
     
    2424use HexCoupon\App\Core\Core;
    2525use HexCoupon\App\Core\Helpers\StoreCredit\StoreCreditBlockSupport;
     26use HexCoupon\App\Controllers\Api\SpinWheelSettingsApiController;
    2627
    2728if ( ! defined( 'ABSPATH' ) ) die();
  • hex-coupon-for-woocommerce/trunk/src/components/utils/tab/Tabs.jsx

    r3142966 r3144677  
    1717   
    1818    const [allProducts, setAllProducts] = useState([]);
    19     const [allCategories, setAllCategories] = useState([]);0
     19    const [allCategories, setAllCategories] = useState([]);
     20    const [allPages, setAllPages] = useState([]);
    2021    const [isLoading, setIsLoading] = useState(true);
    2122    const [selectedUsers, setSelectedUsers] = useState([]);
     
    2324    const [selectedExcludeProducts, setSelectedExcludeProducts] = useState([]);
    2425    const [selectedExcludeCategories, setSelectedExcludeCategories] = useState([]);
     26    const [selectedPages,setSelectedPages] = useState([]);
    2527
    2628    const handleUserSelect = (selectedOptions) => {
     
    3133
    3234    useEffect(() => {
     35        // Fetch all combined data (products, categories) and pages
    3336        axios
    3437            .get(ajaxUrl, {
     
    4245            })
    4346            .then(({ data }) => {
     47                // Format WooCommerce Products
    4448                const formattedProducts = Object.entries(data.allWooCommerceProduct).map(([id, name]) => ({
    4549                    value: id, // The key (product ID) as the value
    4650                    label: name, // The value (product name) as the label
    47                   }));
    48                   setAllProducts(formattedProducts);
    49 
    50                   const formattedCategories = Object.entries(data.allWooCommerceCategories).map(([id, name]) => ({
    51                     value: id, // The key (product ID) as the value
    52                     label: name, // The value (product name) as the label
    53                   }));
    54                   setAllCategories(formattedCategories);
     51                }));
     52                setAllProducts(formattedProducts);
     53   
     54                // Format WooCommerce Categories
     55                const formattedCategories = Object.entries(data.allWooCommerceCategories).map(([id, name]) => ({
     56                    value: id, // The key (category ID) as the value
     57                    label: name, // The value (category name) as the label
     58                }));
     59                setAllCategories(formattedCategories);
     60
     61                const formattedPages = Object.entries(data.allPages).map(([id, title]) => ({
     62                    value: id,
     63                    label: title,
     64                }));
     65                setAllPages(formattedPages);
    5566            })
    5667            .catch((error) => {
     
    5970            .finally(() => setIsLoading(false));
    6071    }, [nonce]);
    61 
    62 
     72   
    6373    const [formData, setFormData] = useState(null);
    6474    const [activeTab, setActiveTab] = useState(0);
     
    8999                ).filter(product => product); // Filter out undefined values
    90100                setSelectedExcludeProducts(excludedProducts);
    91 
     101   
     102                // Fetch selected pages IDs from the API
     103                const selectedPagesId = data.spinWheelSettingsData.spinWheelPopup.selectedPages || [];
     104                // Map selectedPages IDs to the corresponding pages from allPages
     105                const mappedSelectedPages = selectedPagesId.map(pageId => {
     106                    return allPages.find(page => page.value === pageId);
     107                }).filter(page => page); // Remove any undefined entries
     108                setSelectedPages(mappedSelectedPages);
     109   
    92110                // Initialize formData once spinWheelData is available
    93                 const spinWheelContentArray = Object.keys(data.spinWheelSettingsData?.spinWheelContent || {}).map(key => {
     111                let spinWheelContentArray = Object.keys(data.spinWheelSettingsData?.spinWheelContent || {}).map(key => {
    94112                    const item = data.spinWheelSettingsData.spinWheelContent[key];
    95113                    return {
     
    98116                    };
    99117                });
    100 
    101 
     118   
     119                if (spinWheelContentArray.length === 0) {
     120                    spinWheelContentArray = [
     121                        { id: 1, couponType: 'Non', label: 'Not Lucky', value: 0, color: '#ffe0b2' },
     122                        { id: 2, couponType: 'Percentage discount', label: '{coupon_amount} OFF', value: 5, color: '#ec65100' },
     123                        { id: 3, couponType: 'Non', label: 'Not Lucky', value: 0, color: '#ffb74d' },
     124                        { id: 4, couponType: 'Fixed product discount', label: '{coupon_amount} OFF', value: 10, color: '#ff8c00' },
     125                    ];
     126                }               
     127   
    102128                setFormData({
    103129                    tab1: {
     
    109135                        field1: data.spinWheelSettingsData.spinWheelPopup.iconColor,
    110136                        field3: data.spinWheelSettingsData.spinWheelPopup.popupInterval,
    111                         field4: !!data.spinWheelSettingsData.spinWheelPopup.showOnlyHomepage,  // Ensure it's a boolean
    112                         field5: !!data.spinWheelSettingsData.spinWheelPopup.showOnlyBlogPage,    // Ensure it's a boolean
    113                         field6: !!data.spinWheelSettingsData.spinWheelPopup.showOnlyShopPage,    // Ensure it's a boolean
     137                        field4: data.spinWheelSettingsData.spinWheelPopup.showOnlyHomepage, 
     138                        field5: data.spinWheelSettingsData.spinWheelPopup.showOnlyBlogPage, 
     139                        field6: data.spinWheelSettingsData.spinWheelPopup.showOnlyShopPage,   
     140                        field7: data.spinWheelSettingsData.spinWheelPopup.selectedPages,
    114141                    },
    115142                    tab3: {
     
    118145                        textColor: data.spinWheelSettingsData.spinWheelWheel.textColor,
    119146                        wheelDescription: data.spinWheelSettingsData.spinWheelWheel.wheelDescription,
     147                        wheelDescriptionColor: data.spinWheelSettingsData.spinWheelWheel.wheelDescriptionColor,
    120148                        buttonText: data.spinWheelSettingsData.spinWheelWheel.buttonText,
    121149                        buttonColor: data.spinWheelSettingsData.spinWheelWheel.buttonColor,
    122150                        buttonBGColor: data.spinWheelSettingsData.spinWheelWheel.buttonBGColor,
    123151                        enableYourName: data.spinWheelSettingsData.spinWheelWheel.enableYourName,
    124                         yourName: data.spinWheelSettingsData.spinWheelWheel.yourName,
    125                         enablePhoneNumber: data.spinWheelSettingsData.spinWheelWheel.enablePhoneNumber,
    126                         phoneNumber: data.spinWheelSettingsData.spinWheelWheel.phoneNumber,
     152                        yourName: data.spinWheelSettingsData.spinWheelWheel.yourName,                       
    127153                        enableEmailAddress: data.spinWheelSettingsData.spinWheelWheel.enableEmailAddress,
    128154                        emailAddress: data.spinWheelSettingsData.spinWheelWheel.emailAddress,
     
    153179                setSettings(spinWheelContentArray);
    154180            })
    155             .catch( ( error ) => {
    156                 console.error( 'Error:', error );
    157             } );
    158     }, [allCategories, allProducts, nonce] );
     181            .catch((error) => {
     182                console.error('Error:', error);
     183            });
     184    }, [allCategories, allProducts, allPages, nonce]); 
    159185
    160186    const [settings, setSettings] = useState([
     
    184210
    185211    const handleFormChange = (e, tab) => {
    186         const { name, value } = e.target;
    187         setFormData({
    188             ...formData,
    189             [tab]: { ...formData[tab], [name]: value }
    190         });
     212        const { name, type, checked, value } = e.target;
     213        const newValue = type === 'checkbox' ? checked : value;
     214       
     215        setFormData(prevFormData => ({
     216            ...prevFormData,
     217            [tab]: {
     218                ...prevFormData[tab],
     219                [name]: newValue
     220            }
     221        }));
    191222    };
     223   
    192224
    193225    const handleSave = (tab) => {
     
    298330                    showOnlyBlogPage: formData.tab2.field5,
    299331                    showOnlyShopPage: formData.tab2.field6,
     332                    selectedPages: selectedPages.map(page => page.value)
    300333                },
    301334            }, {
     
    329362                    textColor: formData.tab3.textColor, // Text color from color picker
    330363                    wheelDescription: formData.tab3.wheelDescription, // Wheel description from ReactQuill
     364                    wheelDescriptionColor: formData.tab3.wheelDescriptionColor, // wheel description color
    331365                    buttonText: formData.tab3.buttonText, // Button text
    332366                    buttonColor: formData.tab3.buttonColor, // Button color from color picker
    333367                    buttonBGColor: formData.tab3.buttonBGColor,
    334368                    enableYourName: formData.tab3.enableYourName, // Enable Your Name switch
    335                     yourName: formData.tab3.yourName, // Your name
    336                     enablePhoneNumber: formData.tab3.enablePhoneNumber, // Enable Phone Number switch
    337                     phoneNumber: formData.tab3.phoneNumber, // Phone number
    338369                    enableEmailAddress: formData.tab3.enableEmailAddress, // Enable Email Address switch
    339                     emailAddress: formData.tab3.emailAddress, // Email address
    340370                    gdprMessage: formData.tab3.gdprMessage, // GDPR message from ReactQuill
    341371                },
     
    478508                        </div>
    479509                        <div className="general-item">
    480                             <label>{__("Spin per email", "hex-coupon-for-woocommerce-pro")}</label>
     510                            <label>{__("Spin per email(if user spin count exceeds he won't see the spin wheel again)", "hex-coupon-for-woocommerce-pro")}</label>
    481511                            <input
    482512                                type="number"
     
    517547                        </div>
    518548                        <div className="popup-settings">
    519                             <label>{__("If customers close and not spin, show popup again after", "hex-coupon-for-woocommerce-pro")}</label>
     549                            <label>{__("If customers close and not spin, show popup again after(in seconds)", "hex-coupon-for-woocommerce-pro")}</label>
    520550                            <input
    521551                                type="number"
     
    526556                        </div>
    527557                        <div className="popup-settings">
    528                             <label>{__("Show only on Homepage", "hex-coupon-for-woocommerce-pro")}</label>
     558                            <label>{__("Show on Homepage", "hex-coupon-for-woocommerce-pro")}</label>
    529559                            <Switch
    530560                                isChecked={formData?.tab2?.field4}  // Use optional chaining to avoid errors
     
    539569                        </div>
    540570                        <div className="popup-settings">
    541                             <label>{__("Show only on Blog page", "hex-coupon-for-woocommerce-pro")}</label>
     571                            <label>{__("Show on Blog page", "hex-coupon-for-woocommerce-pro")}</label>
    542572                            <Switch
    543573                                isChecked={formData.tab2.field5}
     
    546576                        </div>
    547577                        <div className="popup-settings">
    548                             <label>{__("Show only on Shop page", "hex-coupon-for-woocommerce-pro")}</label>
     578                            <label>{__("Show on Shop page", "hex-coupon-for-woocommerce-pro")}</label>
    549579                            <Switch
    550580                                isChecked={formData.tab2.field6}
     
    552582                            />
    553583                        </div>
     584
     585                        <div className="popup-settings">
     586                            <label>{__("Select Specific Pages", "hex-coupon-for-woocommerce-pro")}</label>
     587                           
     588                            <Select
     589                               
     590                                closeMenuOnSelect={false}
     591                                isMulti
     592                                options={allPages}
     593                                className="mt-2 selectedPages"
     594                                value={selectedPages}
     595                                onChange={setSelectedPages}
     596                            />
     597
     598                           
     599                       
     600
     601                        </div>
     602
     603                       
     604
    554605                        <div className="popup-settings">
    555606                            <label></label>
     
    596647                                type="color"
    597648                                className="colorPicker"
    598                                 value={formData.tab3.textColor}
     649                                value={formData.tab3.wheelDescriptionColor}
    599650                                onChange={(e) => handleFormChange(e, 'tab3')}
    600                                 name="textColor"
     651                                name="wheelDescriptionColor"
    601652                            />
    602653                        </div>
     
    641692                                    onSwitchChange={(isChecked) => setFormData({ ...formData, tab3: { ...formData.tab3, enableYourName: isChecked } })}
    642693                                />
    643                                 <input
    644                                     type="text"
    645                                     name="yourName"
    646                                     placeholder="Enter your name"
    647                                     className="your-name"
    648                                     value={formData.tab3.yourName}
    649                                     onChange={(e) => handleFormChange(e, 'tab3')}
    650                                     disabled={!formData.tab3.enableYourName}
    651                                 />
    652                             </div>
    653                         </div>
    654 
    655                         <div className="wheel-settings">
    656                             <label>{__("Phone Number", "hex-coupon-for-woocommerce")}</label>
    657                             <div className="phone">
    658                                 <Switch
    659                                     isChecked={formData.tab3.enablePhoneNumber}
    660                                     onSwitchChange={(isChecked) => setFormData({ ...formData, tab3: { ...formData.tab3, enablePhoneNumber: isChecked } })}
    661                                 />
    662                                 <input
    663                                     type="text"
    664                                     name="phoneNumber"
    665                                     className="phone"
    666                                     placeholder="Enter your phone number"
    667                                     value={formData.tab3.phoneNumber}
    668                                     onChange={(e) => handleFormChange(e, 'tab3')}
    669                                     disabled={!formData.tab3.enablePhoneNumber}
    670                                 />
    671694                            </div>
    672695                        </div>
     
    679702                                    onSwitchChange={(isChecked) => setFormData({ ...formData, tab3: { ...formData.tab3, enableEmailAddress: isChecked } })}
    680703                                />
    681                                 <input
    682                                     type="email"
    683                                     name="emailAddress"
    684                                     className="email"
    685                                     placeholder="Enter your email address"
    686                                     value={formData.tab3.emailAddress}
    687                                     onChange={(e) => handleFormChange(e, 'tab3')}
    688                                     disabled={!formData.tab3.enableEmailAddress}
    689                                 />
    690704                            </div>
    691705                        </div>
     
    700714
    701715                        <div className="wheel-settings wysiwyg-container">
    702                             <label>{__("GDPR Checkbox Text", "hex-coupon-for-woocommerce-pro")}</label>
     716                            <label></label>
    703717                            <button className="save" type="button" onClick={() => handleSave('tab3')}>
    704718                                {__("Save", "hex-coupon-for-woocommerce-pro")}
  • hex-coupon-for-woocommerce/trunk/src/scss/components/_tabs.scss

    r3142966 r3144677  
    4747            margin-bottom: 20px;
    4848            display: flex;
     49            .selectedPages {
     50                width: 80%;
     51            }
    4952            .save {
    5053                padding: 10px 20px;
     
    6972                width: 200px;
    7073            }
    71             input:not(.colorPicker):not(.your-name):not(.phone):not(.email) {
     74            input:not(.colorPicker):not(.your-name):not(.password):not(.email) {
    7275                width: 80%;
    7376                height: fit-content;
     
    7679                border-radius: 4px;
    7780            }
    78             .name, .phone, .email {
     81            .name, .password, .email {
    7982                flex-grow: 1;
    8083                .switchWrap {
Note: See TracChangeset for help on using the changeset viewer.