Plugin Directory

Changeset 3046723


Ignore:
Timestamp:
03/07/2024 06:04:42 AM (2 years ago)
Author:
wphex
Message:

"Version 1.1.4 released"

Location:
hex-coupon-for-woocommerce
Files:
329 added
1 deleted
10 edited

Legend:

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

    r3046058 r3046723  
    66Requires at least: 5.4
    77Tested up to: 6.4.3
    8 Version: 1.1.3
    9 Stable tag: 1.1.3
     8Version: 1.1.4
     9Stable tag: 1.1.4
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    149149
    150150== Changelog ==
     151== 1.1.4 ==
     152Fixed dynamic time not being saved for wednesday issue.
     153
    151154== 1.1.3 ==
    152155Fixed always displaying shipping zone error while applying the coupon
  • hex-coupon-for-woocommerce/trunk/app/Controllers/AdminMenuController.php

    r3030852 r3046723  
    7272            [ $this, 'render_hexcoupon' ],
    7373            'dashicons-admin-settings',
    74             40
     74            57
    7575        );
    7676    }
  • hex-coupon-for-woocommerce/trunk/app/Controllers/WooCommerce/Admin/Bogo/HexcouponBogoController.php

    r3030852 r3046723  
    126126        }
    127127
    128 
    129         if ( $cart->get_applied_coupons() )
     128        $coupon_discount_type = get_post_meta( $coupon_id, 'discount_type', true );
     129
     130        if ( $cart->get_applied_coupons() && 'buy_x_get_x_bogo' === $coupon_discount_type )
    130131            $cart->add_fee( __( 'Total Bogo Discount', 'hex-coupon-for-woocommerce' ), -$total_subtotal );
    131132
  • hex-coupon-for-woocommerce/trunk/app/Controllers/WooCommerce/Admin/CouponGeneralTabController.php

    r3046058 r3046723  
    2626        add_filter( 'woocommerce_coupon_is_valid', [ $this, 'apply_coupon' ], 10, 2 );
    2727        add_action( 'woocommerce_process_shop_coupon_meta', [ $this, 'delete_meta_value' ] );
     28        add_filter( 'woocommerce_coupon_error', [ $this, 'custom_error_message_for_expiry_date' ], 10, 3 );
     29    }
     30
     31    /**
     32     * @package hexcoupon
     33     * @author WpHex
     34     * @method custom_error_message_for_expiry_date
     35     * @return void
     36     * @since 1.0.0
     37     * Altering the default coupon expiry message with the custom one
     38     */
     39    public function custom_error_message_for_expiry_date( $err_message, $err_code, $coupon ) {
     40        $coupon_id = $coupon->get_id();
     41        $custom_expiry_message = get_post_meta( $coupon_id, 'message_for_coupon_expiry_date', true );
     42
     43        if ( 107 === $err_code && ! empty( $custom_expiry_message ) ) {
     44            $err_message = sprintf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $custom_expiry_message ) );
     45        }
     46
     47        return $err_message;
     48    }
     49
     50    /**
     51     * @package hexcoupon
     52     * @author Wphex
     53     * @since 1.0.0
     54     * @method coupon_starting_date_invalid_error_message
     55     * @param string $err
     56     * @param int $err_code
     57     * @param object $coupon
     58     * @return string
     59     * Display custom error message for invalid coupon.
     60     */
     61    public function coupon_starting_date_invalid_error_message( $err, $err_code, $coupon )
     62    {
     63        $coupon = new \WC_Coupon( $coupon );
     64
     65        // Get the ID of the coupon
     66        $coupon_id = $coupon->get_id();
     67
     68        $message_for_coupon_starting_date = get_post_meta( $coupon_id, 'message_for_coupon_starting_date', true );
     69
     70        if ( $err_code === 100 ) {
     71            if ( ! empty( $message_for_coupon_starting_date ) ) {
     72                // Change the error message for the INVALID_FILTERED error here
     73                $err = sprintf( esc_html__( '%s', 'hex-coupon-for-woocommerce' ), esc_html( $message_for_coupon_starting_date ) );
     74            } else {
     75                $err = esc_html__( 'This coupon has not been started yet. ' );
     76            }
     77        }
     78
     79        return $err;
    2880    }
    2981
     
    288340     * @author WpHex
    289341     * @since 1.0.0
    290      * @method save_coupon_sat_dynamic_start_time
     342     * @method save_coupon_dynamic_start_expiry_time
    291343     * @param $coupon_id
    292344     * @return void
     
    305357            [ 'tuesday', 'tue_coupon_expiry_time_', 'string' ],
    306358            [ 'wednesday', 'wed_coupon_start_time_', 'string' ],
    307             [ 'wednesday', 'wed_coupon_start_time_', 'string' ],
     359            [ 'wednesday', 'wed_coupon_expiry_time_', 'string' ],
    308360            [ 'thursday', 'thu_coupon_start_time_', 'string' ],
    309361            [ 'thursday', 'thu_coupon_expiry_time_', 'string' ],
     
    374426     * @author WpHex
    375427     * @since 1.0.0
     428     * @method apply_coupon_starting_date
     429     * @param bool $valid
     430     * @param object $coupon
     431     * @return bool
     432     * Apply/validate the coupon starting date.
     433     */
     434    private function apply_coupon_starting_date( $valid, $coupon )
     435    {
     436        $current_time = time();
     437
     438        $coupon_starting_date = get_post_meta( $coupon->get_id(), 'coupon_starting_date', true );
     439        $coupon_converted_starting_date = strtotime( $coupon_starting_date );
     440
     441        if ( empty( $coupon_starting_date ) || $current_time >= $coupon_converted_starting_date ) {
     442            return true;
     443        }
     444        else {
     445            // display a custom coupon error message if the coupon is invalid
     446            add_filter( 'woocommerce_coupon_error', [ $this, 'coupon_starting_date_invalid_error_message' ] , 10, 3 );
     447        }
     448    }
     449
     450    /**
     451     * @package hexcoupon
     452     * @author WpHex
     453     * @since 1.0.0
    376454     * @method apply_to_single_day
    377455     * @param bool $valid
     
    382460     * Apply/validate the coupon on different days of the week.
    383461     */
    384     private function apply_to_single_day( $valid, $coupon, $full_day, $abbrev )
     462    private function apply_to_single_day( $valid, $coupon )
    385463    {
    386464        global $day;
     
    388466        // get current date
    389467        $current_day = date('l');
     468        $changed_day = strtolower($current_day);
    390469
    391470        // get current server time
     
    393472
    394473        // get selected name of selected day
    395         $day = get_post_meta( $coupon->get_id(), 'coupon_apply_on_'.$full_day, true );
     474        $day = get_post_meta( $coupon->get_id(), 'coupon_apply_on_'.$changed_day, true );
     475
    396476        $day = ! empty( $day ) ? '1' : '';
    397477        // convert the day name
    398         if ( '1' === $day ) $day = ucfirst( $full_day );
    399 
    400         $coupon_start_time = get_post_meta( $coupon->get_id(), $abbrev.'_coupon_start_time', true );
     478        if ( '1' === $day ) $day = ucfirst( $changed_day );
     479
     480
     481        $first_three_letters = substr( $changed_day, 0, 3 );
     482
     483        $coupon_start_time = get_post_meta( $coupon->get_id(), $first_three_letters.'_coupon_start_time', true );
    401484        $coupon_start_time = strtotime( $coupon_start_time );
    402485
    403         $coupon_expiry_time = get_post_meta( $coupon->get_id(), $abbrev.'_coupon_expiry_time', true );
     486        $coupon_expiry_time = get_post_meta( $coupon->get_id(), $first_three_letters.'_coupon_expiry_time', true );
    404487        $coupon_expiry_time = strtotime( $coupon_expiry_time );
    405488
     
    411494
    412495            // Validating dynamic date and time field after the first field
    413             $total_hours_count = get_post_meta( $coupon->get_id(), 'total_hours_count_'. $full_day, true );
     496            $total_hours_count = get_post_meta( $coupon->get_id(), 'total_hours_count_'. $changed_day, true );
    414497
    415498            for ( $i = 1; $i <= $total_hours_count; $i++ ) {
    416                 $additional_start_time = get_post_meta( $coupon->get_id(), $abbrev . '_coupon_start_time_' . $i, true );
    417                 $additional_expiry_time = get_post_meta( $coupon->get_id(), $abbrev . '_coupon_expiry_time_' . $i, true );
     499                $additional_start_time = get_post_meta( $coupon->get_id(), $first_three_letters . '_coupon_start_time_' . $i, true );
     500                $additional_expiry_time = get_post_meta( $coupon->get_id(), $first_three_letters . '_coupon_expiry_time_' . $i, true );
    418501
    419502                $additional_start_time =  strtotime( $additional_start_time );
     
    439522    private function apply_coupon_on_different_days( $valid, $coupon )
    440523    {
    441         $days = [
    442             'saturday' => 'sat',
    443             'sunday' => 'sun',
    444             'monday' => 'mon',
    445             'tuesday' => 'tue',
    446             'wednesday' => 'wed',
    447             'thursday' => 'thu',
    448             'friday' => 'fri'
    449         ];
    450 
    451         foreach ( $days as $day => $abbrev ) {
    452             if ( ! $this->apply_to_single_day( $valid, $coupon, $day, $abbrev ) ) {
    453                 return false;
    454             } else {
    455                 return true;
    456             }
    457         }
     524        if ( ! $this->apply_to_single_day( $valid, $coupon ) ) {
     525            add_filter( 'woocommerce_coupon_error', [ $this, 'custom_coupon_error_message_for_dynamic_days_and_hours' ] , 10, 2 );
     526
     527            return false;
     528        } else {
     529            return true;
     530        }
     531    }
     532
     533    /**
     534     * @package hexcoupon
     535     * @author Wphex
     536     * @since 1.0.0
     537     * @method custom_coupon_error_message_for_dynamic_days_and_hours
     538     * @param string $err
     539     * @param int $err_code
     540     * @return string
     541     * Display custom error message for invalid coupon.
     542     */
     543    public function custom_coupon_error_message_for_dynamic_days_and_hours( $err, $err_code )
     544    {
     545        if ( $err_code === 100 ) {
     546            // Change the error message for the INVALID_FILTERED error here
     547            $err = esc_html__( 'Coupon is not valid at this hour, please come in another time.', 'hex-coupon-for-woocommerce');
     548        }
     549
     550        return $err;
    458551    }
    459552
     
    472565        // get 'apply_days_hours_of_week' meta value
    473566        $days_hours_of_week = get_post_meta( $coupon->get_id(), 'apply_days_hours_of_week', true );
     567
     568        // get 'apply_coupon_starting_date' return value
     569        $apply_coupon_starting_date = $this->apply_coupon_starting_date( $valid, $coupon );
    474570
    475571        // get 'apply_coupon_on_different_days' return value
     
    486582        ];
    487583
    488         if ( 'yes' === $days_hours_of_week ) {
    489             if ( $apply_coupon_on_different_days ) {
    490                 return $valid;
    491             }
    492 
    493             foreach ( $coupon_apply_on_every_day as $single_day ) {
    494                 $single_day = get_post_meta( $coupon->get_id(), $single_day, true );
    495                 if ( '1' == $single_day ) {
    496                     return false;
     584        if ( $apply_coupon_starting_date ) {
     585            if ('yes' === $days_hours_of_week) {
     586                if ($apply_coupon_on_different_days) {
     587                    return $valid;
    497588                }
    498             }
     589
     590                foreach ($coupon_apply_on_every_day as $single_day) {
     591                    $single_day = get_post_meta($coupon->get_id(), $single_day, true);
     592                    if ('1' == $single_day) {
     593                        return false;
     594                    }
     595                }
     596            }
     597            return true;
    499598        }
    500599
  • hex-coupon-for-woocommerce/trunk/app/Controllers/WooCommerce/Admin/CouponGeographicRestrictionTabController.php

    r3046058 r3046723  
    231231    public function apply_coupon_meta_data( $valid, $coupon )
    232232    {
     233        $payment_shipping_method = PaymentAndShippingTabController::getInstance()->apply_coupon_meta_data( $valid, $coupon );
     234
    233235        $restricted_shipping_zones = $this->restrict_selected_shipping_zones_to_coupon( $valid, $coupon );
    234236
     
    255257        if ( is_null( $restricted_shipping_zones ) || is_null( $restrict_shipping_countries ) ) {
    256258            return $valid;
     259        }
     260
     261        if ( ! $payment_shipping_method ) {
     262            // display a custom coupon error message if the coupon is invalid
     263            add_filter( 'woocommerce_coupon_error', [ $this, 'custom_coupon_error_message_for_payment_and_shipping_method' ] , 10, 2 );
     264
     265            return false;
    257266        }
    258267
     
    300309    }
    301310
     311    /**
     312     * @package hexcoupon
     313     * @author Wphex
     314     * @since 1.0.0
     315     * @method custom_coupon_error_message_for_payment_and_shipping_method
     316     * @param string $err
     317     * @param int $err_code
     318     * @return string
     319     * Display custom error message for invalid coupon.
     320     */
     321    public function custom_coupon_error_message_for_payment_and_shipping_method( $err, $err_code ) {
     322        if ( $err_code === 100 ) {
     323            // Change the error message for the INVALID_FILTERED error here
     324            $err = esc_html__( 'Invalid coupon. Your payment or shipping method does not support this coupon.', 'hex-coupon-for-woocommerce');
     325        }
     326
     327        return $err;
     328    }
    302329}
  • hex-coupon-for-woocommerce/trunk/app/Controllers/WooCommerce/Admin/PaymentAndShippingTabController.php

    r3046058 r3046723  
    2424    {
    2525        add_action( 'woocommerce_process_shop_coupon_meta', [ $this, 'save_coupon_all_meta_data' ] );
    26         add_filter( 'woocommerce_coupon_is_valid', [ $this, 'apply_coupon_meta_data' ], 10, 2 );
     26//      add_filter( 'woocommerce_coupon_is_valid', [ $this, 'apply_coupon_meta_data' ], 10, 2 );
    2727    }
    2828
     
    9090        $selected_permitted_payment_methods = ! empty( $payment_and_shipping['permitted_payment_methods'] ) ? $payment_and_shipping['permitted_payment_methods'] : [];
    9191
     92        // get current payment method of customer
     93        $current_payment_method = WC()->session->get( 'chosen_payment_method' );
     94
    9295        // check if is it empty
    9396        if ( empty( $selected_permitted_payment_methods ) ) {
    9497            return true;
    9598        }
    96 
    97         // get current payment method of customer
    98         $current_payment_method = WC()->session->get( 'chosen_payment_method' );
    9999
    100100        // check if the current payment method matches with the selected payment methods
     
    164164            return true;
    165165        }
     166
    166167        if ( ! $selectedPaymentMethod ) {
    167             // display a custom coupon error message if the coupon is invalid
    168             add_filter( 'woocommerce_coupon_error', [ $this, 'error_message_for_invalid_payment_method' ] , 10, 2 );
    169 
    170168            return false;
    171169        }
    172170        if ( ! $selectedShippingMethods ) {
    173             // display a custom coupon error message if the coupon is invalid
    174             add_filter( 'woocommerce_coupon_error', [ $this, 'error_message_for_invalid_shipping_method' ] , 10, 2 );
    175 
    176171            return false;
    177172        }
    178173    }
    179 
    180     /**
    181      * @package hexcoupon
    182      * @author Wphex
    183      * @since 1.0.0
    184      * @method error_message_for_invalid_payment_method
    185      * @param string $err
    186      * @param int $err_code
    187      * @return string
    188      * Display custom error message for invalid coupon.
    189      */
    190     public function error_message_for_invalid_payment_method( $err, $err_code )
    191     {
    192         if ( $err_code === 100 ) {
    193             // Change the error message for the INVALID_FILTERED error here
    194             $err = esc_html__( 'Invalid coupon. Your payment method does not support this coupon.', 'hex-coupon-for-woocommerce');
    195         }
    196 
    197         return $err;
    198     }
    199 
    200     /**
    201      * @package hexcoupon
    202      * @author Wphex
    203      * @since 1.0.0
    204      * @method error_message_for_invalid_shipping_method
    205      * @param string $err
    206      * @param int $err_code
    207      * @return string
    208      * Display custom error message for invalid coupon.
    209      */
    210     public function error_message_for_invalid_shipping_method( $err, $err_code )
    211     {
    212         if ( $err_code === 100 ) {
    213             // Change the error message for the INVALID_FILTERED error here
    214             $err = esc_html__( 'Invalid coupon. Your shipping method does not support this coupon.', 'hex-coupon-for-woocommerce');
    215         }
    216 
    217         return $err;
    218     }
    219174}
  • hex-coupon-for-woocommerce/trunk/app/Core/Core.php

    r3046058 r3046723  
    66use HexCoupon\App\Controllers\AjaxApiController;
    77use HexCoupon\App\Controllers\WooCommerce\Admin\CouponGeneralTabController;
    8 use HexCoupon\App\Controllers\WooCommerce\Admin\CouponStartingDateController;
    98use HexCoupon\App\Controllers\WooCommerce\Admin\PaymentAndShippingTabController;
    109use HexCoupon\App\Controllers\WooCommerce\Admin\CouponSharableUrlTabController;
     
    6261            CouponSingleGeneralTab::class,
    6362            CouponGeneralTabController::class,
    64             CouponStartingDateController::class,
    6563            CouponSingleGeographicRestrictions::class,
    6664            CouponGeographicRestrictionTabController::class,
  • hex-coupon-for-woocommerce/trunk/app/Core/WooCommerce/CouponPaymentandShipping.php

    r3030852 r3046723  
    8989    public function add_custom_coupon_tab( $tabs )
    9090    {
    91         $tabs['custom_coupon_tab'] = array(
     91        $tabs['custom_coupon_tab'] = [
    9292            'label'    => esc_html__( 'Payment & shipping method', 'hex-coupon-for-woocommerce' ),
    9393            'target'   => 'custom_coupon_tab',
    9494            'class'    => array( 'show_if_coupon_usage_limits' ),
    95         );
     95        ];
    9696        return $tabs;
    9797    }
  • hex-coupon-for-woocommerce/trunk/configs/config.php

    r3046058 r3046723  
    1010    'plugin_slug'       => 'hexcoupon',
    1111    'namaspace_root'    => 'HexCoupon',
    12     'plugin_version'    => '1.1.3',
     12    'plugin_version'    => '1.1.4',
    1313    'plugin_name'       => 'HexCoupon',
    1414    'dev_mode'          => false,
  • hex-coupon-for-woocommerce/trunk/hex-coupon-for-woocommerce.php

    r3046058 r3046723  
    66 * Plugin URI: https://wordpress.org/plugins/hex-coupon-for-woocommerce
    77 * Description: Extend coupon functionality in your Woocommerce store.
    8  * Version: 1.1.3
     8 * Version: 1.1.4
    99 * Author: WpHex
    1010 * Requires at least: 5.4
Note: See TracChangeset for help on using the changeset viewer.