Plugin Directory

Changeset 2315109


Ignore:
Timestamp:
05/30/2020 05:07:56 PM (6 years ago)
Author:
motpr355
Message:

1.0.9 version

Location:
woo-sale-product-date-info
Files:
4 added
4 deleted
14 edited
1 copied

Legend:

Unmodified
Added
Removed
  • woo-sale-product-date-info/tags/1.0.9/css/admin.css

    r1917801 r2315109  
    1 #motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_info_classic {
    2     background: black;color: white;border-radius: 25px;padding: 4px 10px;display: inline-block;
     1#motpr355_woo_sale_product_date_info .motpr355_woo_sale_product_date_info_classic {
     2    background: black;
     3    color: white;
     4    border-radius: 25px;
     5    padding: 4px 10px;
     6    display: inline-block;
     7    margin-bottom: 3px;
    38}
    49
     
    2530    position: relative;
    2631    display: none;
     32    animation: motpr355_woo_sale_product_date_info_activate_arrow_blink 1s infinite;
     33}
     34
     35@keyframes motpr355_woo_sale_product_date_info_activate_arrow_blink {
     36    0% { opacity:0; }
     37    50% { opacity:1; }
     38    100% { opacity:0; }
    2739}
    2840
  • woo-sale-product-date-info/tags/1.0.9/css/website.php

    r1917801 r2315109  
    1313        font-weight: <?php echo esc_html( $this->settings->{$this->settings_enum->font_weight} ) ?>;
    1414        text-transform: <?php echo esc_html( $this->settings->{$this->settings_enum->text_transform} ) ?>;
     15        text-align: center;
    1516        border-radius: 25px;
    1617        padding: 4px 10px;
    17         display: inline-block; 
     18        display: inline-block;
    1819    }
    1920</style>
  • woo-sale-product-date-info/tags/1.0.9/html/admin.php

    r2019865 r2315109  
    33    exit;
    44}
     5$example_start_date = date_i18n( get_option( 'date_format' ), time() - 432000 );
     6$example_end_date = date_i18n( get_option( 'date_format' ), time() + 432000 );
    57?>
    68<div class="wrap" id="motpr355_woo_sale_product_date_info">
     
    1012    </h1>
    1113
    12     <h3><?php _e( 'Display WooCommerce products sale end date.', 'woo-sale-product-date-info' ) ?></h3>
     14    <h3><?php _e( 'Display WooCommerce sale product date.', 'woo-sale-product-date-info' ) ?></h3>
    1315
    1416    <noscript>
     
    121123            </span>
    122124        </p>
     125        <p>
     126            <span>
     127                <?php _e( 'Display:', 'woo-sale-product-date-info' ) ?>
     128            </span>
     129            <span>
     130                <label>
     131                    <input type="radio"
     132                        name="<?php echo $this->settings_enum->display ?>"
     133                        value="<?php echo $this->display_enum->start_date ?>">
     134                    <span><?php _e( 'Only sale start date', 'woo-sale-product-date-info' ) ?></span>
     135                </label>
     136                <label>
     137                    <input type="radio"
     138                        name="<?php echo $this->settings_enum->display ?>"
     139                        value="<?php echo $this->display_enum->end_date ?>">
     140                    <span><?php _e( 'Only sale end date', 'woo-sale-product-date-info' ) ?></span>
     141                </label>
     142                <label>
     143                    <input type="radio"
     144                        name="<?php echo $this->settings_enum->display ?>"
     145                        value="<?php echo $this->display_enum->start_end_date ?>">
     146                    <span><?php _e( 'Sale start and end date', 'woo-sale-product-date-info' ) ?></span>
     147                </label>
     148            </span>
     149        </p>
    123150        <hr/>
    124151        <p>
     
    127154            </span>
    128155            <span>
    129                 <span id="motpr355_woo_sale_product_date_info_classic">
    130                     <?php printf( __( "Until %s", 'woo-sale-product-date-info' ), date_i18n( get_option( 'date_format' ), time() ) ) ?>
     156                <span class="motpr355_woo_sale_product_date_info_classic" id="motpr355_woo_sale_product_date_display_start">
     157                    <?php printf( __( "On sale from %s", 'woo-sale-product-date-info' ), $example_start_date ) ?>
     158                </span>
     159                <span class="motpr355_woo_sale_product_date_info_classic" id="motpr355_woo_sale_product_date_display_end">
     160                    <?php printf( __( "On sale until %s", 'woo-sale-product-date-info' ), $example_end_date ) ?>
     161                </span>
     162                <span class="motpr355_woo_sale_product_date_info_classic" id="motpr355_woo_sale_product_date_display_start_end">
     163                    <?php printf( __( "On sale from %s to %s", 'woo-sale-product-date-info' ), $example_start_date, $example_end_date ) ?>
    131164                </span>
    132165            </span>
  • woo-sale-product-date-info/tags/1.0.9/html/website.php

    r2019865 r2315109  
    66<div class="motpr355_woo_sale_product_date_info_div">
    77    <span class="motpr355_woo_sale_product_date_info_span">
    8         <?php _e( "On sale until %s", 'woo-sale-product-date-info' ) ?>
     8        CONTENT
    99    </span>
    1010</div>
  • woo-sale-product-date-info/tags/1.0.9/js/admin.js

    r1917801 r2315109  
    1010            init_font_weight();
    1111            init_text_transform();
     12            init_display();
    1213            init_preview();
    1314        };
     
    3637        };
    3738
     39        var init_display = function() {
     40            init_value( 'display' );
     41        };
     42
    3843        var init_preview = function() {
    3944            set_preview(
     
    4146                settings.color,
    4247                settings.font_weight,
    43                 settings.text_transform
     48                settings.text_transform,
     49                settings.display
    4450            );
    4551        };
     
    6167        };
    6268
     69        var get_display = function() {
     70            return get_value( 'display' );
     71        };
     72
    6373        var refresh_preview = function() {
    6474            set_preview(
     
    6676                get_color(),
    6777                get_font_weight(),
    68                 get_text_transform()
     78                get_text_transform(),
     79                get_display()
    6980            );
    7081        };
     
    7283        var get_value = function( id ) {
    7384            var text_values = [ 'background_color', 'color' ];
    74             var radio_values = [ 'font_weight', 'text_transform' ];
     85            var radio_values = [ 'font_weight', 'text_transform', 'display' ];
    7586            var element = '#motpr355_woo_sale_product_date_info input[name="' + id + '"]';
    7687            if ( radio_values.indexOf( id ) !== -1 ) {
     
    8495        var init_value = function( id ) {
    8596            var text_values = [ 'background_color', 'color' ];
    86             var radio_values = [ 'activation', 'font_weight', 'text_transform' ];
     97            var radio_values = [ 'activation', 'font_weight', 'text_transform', 'display' ];
    8798            var element = '#motpr355_woo_sale_product_date_info [name="' + id + '"]';
    8899            if ( radio_values.indexOf( id ) !== -1 ) {
     
    94105        };
    95106
    96         var set_preview = function( background_color, color, font_weight, text_transform ) {
     107        var set_preview = function( background_color, color, font_weight, text_transform, display ) {
     108            var start = '#motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_display_start';
     109            var end = '#motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_display_end';
     110            var start_end = '#motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_display_start_end';
     111            var show = '';
     112            var hide = '';
     113            if (display === 'start_date') {
     114                show = start;
     115                hide = end + ',' + start_end;
     116            } else if (display === 'end_date') {
     117                show = end;
     118                hide = start + ',' + start_end;
     119            } else {
     120                show = end + ',' + start + ',' + start_end;
     121                hide = '';
     122            }
     123            $( show ).show();
     124            $( hide ).hide();
    97125            if ( check_color_format( background_color ) && check_color_format( color ) ) {
    98                 var element = '#motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_info_classic';
     126                var element = '#motpr355_woo_sale_product_date_info .motpr355_woo_sale_product_date_info_classic';
    99127                $( element ).css( {
    100128                    backgroundColor: background_color,
  • woo-sale-product-date-info/tags/1.0.9/readme.txt

    r2090705 r2315109  
    33Tags: WooCommerce, E-commerce, product, sale date product, sale date product list, product list, sale date product tag, sale date product info, WooCommerce product
    44Requires at least: 4.0
    5 Tested up to: 5.2
     5Tested up to: 5.4
    66Requires PHP : 5.4
    7 Stable tag: 1.0.8
     7Stable tag: 1.0.9
    88License: GPLv2 or later
    99
    10 Display a customizable sale end date tag for WooCommerce products.
     10Display a customizable sale date tag for WooCommerce products.
    1111
    1212
     
    2626This plugin is fully free ; no hidden features, no premium features, no ads, no account creation... Just a **free plugin made with love by Motpr355**.
    2727
    28 This plugin allow you to display a customizable  customizable sale end date tag for WooCommerce products.
     28This plugin allow you to display a customizable sale date tag for WooCommerce products.
    2929
    3030You can customize your tag in the plugin settings.
     
    3434- Choose tag color with a color picker
    3535- Choose font weight between normal and bold
    36 - Choose text transform. Examples: "Until 2018-10-01", "until 2018-10-01", "UNTIL 2018-10-01". Date format is the one defined in WordPress Settings > General.
     36- Choose text transform. Examples: "On sale until 2018-10-01", "ON SALE UNTIL 2018-10-01"... Date format is the one defined in WordPress Settings > General.
     37- Choose if you want to display sale start date, end date, or both
    3738- Preview the tag before save configuration
    3839
     
    6061== Changelog ==
    6162
     63= 1.0.9 =
     64* Display product sale start date option
     65* Translations update
     66
    6267= 1.0.7 =
    6368* Translations update
  • woo-sale-product-date-info/tags/1.0.9/woo-sale-product-date-info.php

    r2090705 r2315109  
    22/*
    33Plugin Name: WooCommerce sale product date info
    4 Description: Display a customizable sale end date tag for WooCommerce products.
    5 Version: 1.0.8
     4Description: Display a customizable sale date tag for WooCommerce products.
     5Version: 1.0.9
    66Author: Motpr355
    77Text Domain: woo-sale-product-date-info
     
    1818    private $font_weight_enum;
    1919    private $text_transform_enum;
     20    private $display_enum;
    2021
    2122    public function __construct() {
     
    5354
    5455    private function init_data() {
    55         $this->configuration_saved = false;
    56         $this->settings = $this->get_settings();
    5756        $this->settings_enum = ( object ) array(
    5857            'nonce' => 'nonce',
     
    6160            'color' => 'color',
    6261            'font_weight' => 'font_weight',
    63             'text_transform' => 'text_transform'
     62            'text_transform' => 'text_transform',
     63            'display' => 'display'
    6464        );
    6565        $this->activation_enum = ( object ) array(
     
    7676            'uppercase' => 'uppercase'
    7777        );
     78        $this->display_enum = ( object ) array(
     79            'start_date' => 'start_date',
     80            'end_date' => 'end_date',
     81            'start_end_date' => 'start_end_date'
     82        );
     83
     84        $this->configuration_saved = false;
     85        $this->settings = $this->get_settings();
    7886    }
    7987
     
    96104            $this->settings->{$this->settings_enum->color},
    97105            $this->settings->{$this->settings_enum->font_weight},
    98             $this->settings->{$this->settings_enum->text_transform} ) ) {
     106            $this->settings->{$this->settings_enum->text_transform},
     107            $this->settings->{$this->settings_enum->display} ) ) {
    99108            include plugin_dir_path( __FILE__ ) . 'css/website.php';
    100         }   
     109        }
    101110    }
    102111
     
    106115            if ( $product->is_on_sale() ) {
    107116                if ( function_exists( 'get_post_meta' ) && function_exists( 'get_the_ID' ) && function_exists( 'date_i18n' ) ) {
    108                     $date = get_post_meta( get_the_ID(), '_sale_price_dates_to', true );
    109                     if ( $date && is_string( $date ) ) {
    110                             $date = date_i18n( get_option( 'date_format' ), $date );
    111                         if ( isset ( $this->display_info_content ) ) {
    112                             return str_replace( '%s', $date, $this->display_info_content );
    113                         }
    114                         if ( function_exists( 'ob_start' ) && function_exists( 'ob_get_clean' ) ) {
    115                             ob_start();
    116                             include plugin_dir_path( __FILE__ ) . 'html/website.php';
    117                             $this->display_info_content = ob_get_clean();
    118                             return str_replace( '%s', $date, $this->display_info_content );
     117                    $date_format = get_option( 'date_format' );
     118                    if ( $date_format !== false ) {
     119                        if ( method_exists( $product, 'get_date_on_sale_from' ) && method_exists( $product, 'get_date_on_sale_to' ) ) {
     120                            $begin_date_display = false;
     121                            $begin_date = $product->get_date_on_sale_from( 'edit' );
     122                            if ( $begin_date && method_exists( $begin_date, 'getOffsetTimestamp' ) ) {
     123                                $begin_date_display = date_i18n( $date_format, $begin_date->getOffsetTimestamp() );
     124                            }
     125                            $end_date_display = false;
     126                            $end_date = $product->get_date_on_sale_to( 'edit' );
     127                            if ( $end_date && method_exists( $end_date, 'getOffsetTimestamp' ) ) {
     128                                $end_date_display = date_i18n( $date_format, $end_date->getOffsetTimestamp() );
     129                            }
     130                            if ( $begin_date_display || $end_date_display ) {
     131                                if ( isset ( $this->settings->{$this->settings_enum->background_color},
     132                                    $this->settings->{$this->settings_enum->color},
     133                                    $this->settings->{$this->settings_enum->font_weight},
     134                                    $this->settings->{$this->settings_enum->text_transform},
     135                                    $this->settings->{$this->settings_enum->display}) ) {
     136                                    $display_option = $this->settings->{$this->settings_enum->display};
     137                                    $text = false;
     138                                    if ( $begin_date_display && $end_date_display ) {
     139                                        if ( $display_option === $this->display_enum->start_date ) {
     140                                            $text = sprintf( __( 'On sale from %s', 'woo-sale-product-date-info' ), $begin_date_display );
     141                                        } else if ( $display_option === $this->display_enum->end_date ) {
     142                                            $text = sprintf( __( 'On sale until %s', 'woo-sale-product-date-info' ), $end_date_display );
     143                                        } else if ( $display_option === $this->display_enum->start_end_date ) {
     144                                            $text = sprintf( __( 'On sale from %s to %s', 'woo-sale-product-date-info' ), $begin_date_display, $end_date_display );
     145                                        }
     146                                    } else if ( $begin_date_display && ! $end_date_display ) {
     147                                        if ( $display_option === $this->display_enum->start_date || $display_option === $this->display_enum->start_end_date ) {
     148                                            $text = sprintf( __( 'On sale from %s', 'woo-sale-product-date-info' ), $begin_date_display );
     149                                        }
     150                                    } else if ( ! $begin_date_display && $end_date_display ) {
     151                                        if ( $display_option === $this->display_enum->end_date || $display_option === $this->display_enum->start_end_date ) {
     152                                            $text = sprintf( __( 'On sale until %s', 'woo-sale-product-date-info' ), $end_date_display );
     153                                        }
     154                                    }
     155                                    if ( $text !== false ) {
     156                                        if ( isset ( $this->display_info_content ) ) {
     157                                            return str_replace( 'CONTENT', $text, $this->display_info_content );
     158                                        }
     159                                        if ( function_exists( 'ob_start' ) && function_exists( 'ob_get_clean' ) ) {
     160                                            ob_start();
     161                                            include plugin_dir_path( __FILE__ ) . 'html/website.php';
     162                                            $this->display_info_content = ob_get_clean();
     163                                            return str_replace( 'CONTENT', $text, $this->display_info_content );
     164                                        }
     165                                    }
     166                                }
     167                            }
    119168                        }
    120169                    }
     
    143192            'color' => '#ffffff',
    144193            'font_weight' => 'bold',
    145             'text_transform' => 'none'
     194            'text_transform' => 'none',
     195            'display' => 'end_date'
    146196        );
    147197        update_option( 'motpr355_woo_sale_product_date_info_settings', $settings );
     
    149199
    150200    public function installed( $plugin ) {
    151         if( $plugin === plugin_basename( __FILE__ ) ) {
    152         exit( wp_redirect( admin_url( 'edit.php?post_type=product&page=motpr355_woo_sale_product_date_info' ) ) );
    153         }
     201        if( $plugin === plugin_basename( __FILE__ ) && is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
     202            exit( wp_redirect( admin_url( 'edit.php?post_type=product&page=motpr355_woo_sale_product_date_info' ) ) );
     203        }
    154204    }
    155205
     
    201251                    plugins_url( 'js/admin.js', __FILE__ ),
    202252                    array( 'wp-color-picker' ),
    203                     '1.0.0',
     253                    '1.0.9',
    204254                    true
    205255                );
     
    214264                    plugins_url( 'js/admin-extensions.js', __FILE__ ),
    215265                    array(),
    216                     '1.0.0',
     266                    '1.0.9',
    217267                    true
    218268                );
     
    221271                    'motpr355_woo_sale_product_date_info_translations',
    222272                    array(
    223                         'woo_inactive' => __( 
     273                        'woo_inactive' => __(
    224274                            'WooCommerce must be actived',
    225275                            'woo-sale-product-date-info'
     
    242292                plugins_url( 'css/admin.css', __FILE__ ),
    243293                array(),
    244                 '1.0.0'
     294                '1.0.9'
    245295            );
    246296            wp_enqueue_style( 'motpr355_woo_sale_product_date_info_style' );
     
    268318    private function save_configuration() {
    269319        if ( isset ( $_POST[ 'nonce' ], $_POST[ 'activation' ], $_POST[ 'background_color' ],
    270             $_POST[ 'color' ], $_POST[ 'font_weight' ], $_POST[ 'text_transform' ] ) ) {
     320            $_POST[ 'color' ], $_POST[ 'font_weight' ], $_POST[ 'text_transform' ], $_POST[ 'display' ] ) ) {
    271321            $nonce = $this->get_cleaned_posted_data( $_POST[ 'nonce' ] );
    272322            $saved_nonce = $this->settings->{$this->settings_enum->nonce};
     
    277327                $font_weight = $this->get_cleaned_font_weight( $_POST[ 'font_weight' ] );
    278328                $text_transform = $this->get_cleaned_text_transform( $_POST[ 'text_transform' ] );
     329                $display = $this->get_cleaned_display( $_POST[ 'display' ] );
    279330                if ( $activation !== false && $background_color !== false && $color !== false
    280                     && $font_weight !== false && $text_transform !== false ) {
     331                    && $font_weight !== false && $text_transform !== false && $display !== false ) {
    281332                    $settings = array(
    282333                        'nonce' => $saved_nonce,
     
    285336                        'color' => $color,
    286337                        'font_weight' => $font_weight,
    287                         'text_transform' => $text_transform
     338                        'text_transform' => $text_transform,
     339                        'display' => $display
    288340                    );
    289341                    update_option( 'motpr355_woo_sale_product_date_info_settings', $settings );
     
    320372    }
    321373
     374    private function get_cleaned_display( $display ) {
     375        $display = $this->get_cleaned_posted_data( $display );
     376        return in_array( $display, ( array ) $this->display_enum ) ? $display : false;
     377    }
     378
    322379    private function get_cleaned_posted_data( $data ) {
    323380        return stripslashes_deep( sanitize_text_field( $data ) );
     
    337394
    338395    private function get_settings() {
    339         return ( object ) get_option( 'motpr355_woo_sale_product_date_info_settings', array() );
     396        $settings = ( object ) get_option( 'motpr355_woo_sale_product_date_info_settings', array() );
     397        if ( ! isset ( $settings->display ) ) {
     398            $settings->display = $this->display_enum->end_date;
     399        }
     400        return $settings;
    340401    }
    341402
  • woo-sale-product-date-info/trunk/css/admin.css

    r1917801 r2315109  
    1 #motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_info_classic {
    2     background: black;color: white;border-radius: 25px;padding: 4px 10px;display: inline-block;
     1#motpr355_woo_sale_product_date_info .motpr355_woo_sale_product_date_info_classic {
     2    background: black;
     3    color: white;
     4    border-radius: 25px;
     5    padding: 4px 10px;
     6    display: inline-block;
     7    margin-bottom: 3px;
    38}
    49
     
    2530    position: relative;
    2631    display: none;
     32    animation: motpr355_woo_sale_product_date_info_activate_arrow_blink 1s infinite;
     33}
     34
     35@keyframes motpr355_woo_sale_product_date_info_activate_arrow_blink {
     36    0% { opacity:0; }
     37    50% { opacity:1; }
     38    100% { opacity:0; }
    2739}
    2840
  • woo-sale-product-date-info/trunk/css/website.php

    r1917801 r2315109  
    1313        font-weight: <?php echo esc_html( $this->settings->{$this->settings_enum->font_weight} ) ?>;
    1414        text-transform: <?php echo esc_html( $this->settings->{$this->settings_enum->text_transform} ) ?>;
     15        text-align: center;
    1516        border-radius: 25px;
    1617        padding: 4px 10px;
    17         display: inline-block; 
     18        display: inline-block;
    1819    }
    1920</style>
  • woo-sale-product-date-info/trunk/html/admin.php

    r2019865 r2315109  
    33    exit;
    44}
     5$example_start_date = date_i18n( get_option( 'date_format' ), time() - 432000 );
     6$example_end_date = date_i18n( get_option( 'date_format' ), time() + 432000 );
    57?>
    68<div class="wrap" id="motpr355_woo_sale_product_date_info">
     
    1012    </h1>
    1113
    12     <h3><?php _e( 'Display WooCommerce products sale end date.', 'woo-sale-product-date-info' ) ?></h3>
     14    <h3><?php _e( 'Display WooCommerce sale product date.', 'woo-sale-product-date-info' ) ?></h3>
    1315
    1416    <noscript>
     
    121123            </span>
    122124        </p>
     125        <p>
     126            <span>
     127                <?php _e( 'Display:', 'woo-sale-product-date-info' ) ?>
     128            </span>
     129            <span>
     130                <label>
     131                    <input type="radio"
     132                        name="<?php echo $this->settings_enum->display ?>"
     133                        value="<?php echo $this->display_enum->start_date ?>">
     134                    <span><?php _e( 'Only sale start date', 'woo-sale-product-date-info' ) ?></span>
     135                </label>
     136                <label>
     137                    <input type="radio"
     138                        name="<?php echo $this->settings_enum->display ?>"
     139                        value="<?php echo $this->display_enum->end_date ?>">
     140                    <span><?php _e( 'Only sale end date', 'woo-sale-product-date-info' ) ?></span>
     141                </label>
     142                <label>
     143                    <input type="radio"
     144                        name="<?php echo $this->settings_enum->display ?>"
     145                        value="<?php echo $this->display_enum->start_end_date ?>">
     146                    <span><?php _e( 'Sale start and end date', 'woo-sale-product-date-info' ) ?></span>
     147                </label>
     148            </span>
     149        </p>
    123150        <hr/>
    124151        <p>
     
    127154            </span>
    128155            <span>
    129                 <span id="motpr355_woo_sale_product_date_info_classic">
    130                     <?php printf( __( "Until %s", 'woo-sale-product-date-info' ), date_i18n( get_option( 'date_format' ), time() ) ) ?>
     156                <span class="motpr355_woo_sale_product_date_info_classic" id="motpr355_woo_sale_product_date_display_start">
     157                    <?php printf( __( "On sale from %s", 'woo-sale-product-date-info' ), $example_start_date ) ?>
     158                </span>
     159                <span class="motpr355_woo_sale_product_date_info_classic" id="motpr355_woo_sale_product_date_display_end">
     160                    <?php printf( __( "On sale until %s", 'woo-sale-product-date-info' ), $example_end_date ) ?>
     161                </span>
     162                <span class="motpr355_woo_sale_product_date_info_classic" id="motpr355_woo_sale_product_date_display_start_end">
     163                    <?php printf( __( "On sale from %s to %s", 'woo-sale-product-date-info' ), $example_start_date, $example_end_date ) ?>
    131164                </span>
    132165            </span>
  • woo-sale-product-date-info/trunk/html/website.php

    r2019865 r2315109  
    66<div class="motpr355_woo_sale_product_date_info_div">
    77    <span class="motpr355_woo_sale_product_date_info_span">
    8         <?php _e( "On sale until %s", 'woo-sale-product-date-info' ) ?>
     8        CONTENT
    99    </span>
    1010</div>
  • woo-sale-product-date-info/trunk/js/admin.js

    r1917801 r2315109  
    1010            init_font_weight();
    1111            init_text_transform();
     12            init_display();
    1213            init_preview();
    1314        };
     
    3637        };
    3738
     39        var init_display = function() {
     40            init_value( 'display' );
     41        };
     42
    3843        var init_preview = function() {
    3944            set_preview(
     
    4146                settings.color,
    4247                settings.font_weight,
    43                 settings.text_transform
     48                settings.text_transform,
     49                settings.display
    4450            );
    4551        };
     
    6167        };
    6268
     69        var get_display = function() {
     70            return get_value( 'display' );
     71        };
     72
    6373        var refresh_preview = function() {
    6474            set_preview(
     
    6676                get_color(),
    6777                get_font_weight(),
    68                 get_text_transform()
     78                get_text_transform(),
     79                get_display()
    6980            );
    7081        };
     
    7283        var get_value = function( id ) {
    7384            var text_values = [ 'background_color', 'color' ];
    74             var radio_values = [ 'font_weight', 'text_transform' ];
     85            var radio_values = [ 'font_weight', 'text_transform', 'display' ];
    7586            var element = '#motpr355_woo_sale_product_date_info input[name="' + id + '"]';
    7687            if ( radio_values.indexOf( id ) !== -1 ) {
     
    8495        var init_value = function( id ) {
    8596            var text_values = [ 'background_color', 'color' ];
    86             var radio_values = [ 'activation', 'font_weight', 'text_transform' ];
     97            var radio_values = [ 'activation', 'font_weight', 'text_transform', 'display' ];
    8798            var element = '#motpr355_woo_sale_product_date_info [name="' + id + '"]';
    8899            if ( radio_values.indexOf( id ) !== -1 ) {
     
    94105        };
    95106
    96         var set_preview = function( background_color, color, font_weight, text_transform ) {
     107        var set_preview = function( background_color, color, font_weight, text_transform, display ) {
     108            var start = '#motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_display_start';
     109            var end = '#motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_display_end';
     110            var start_end = '#motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_display_start_end';
     111            var show = '';
     112            var hide = '';
     113            if (display === 'start_date') {
     114                show = start;
     115                hide = end + ',' + start_end;
     116            } else if (display === 'end_date') {
     117                show = end;
     118                hide = start + ',' + start_end;
     119            } else {
     120                show = end + ',' + start + ',' + start_end;
     121                hide = '';
     122            }
     123            $( show ).show();
     124            $( hide ).hide();
    97125            if ( check_color_format( background_color ) && check_color_format( color ) ) {
    98                 var element = '#motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_info_classic';
     126                var element = '#motpr355_woo_sale_product_date_info .motpr355_woo_sale_product_date_info_classic';
    99127                $( element ).css( {
    100128                    backgroundColor: background_color,
  • woo-sale-product-date-info/trunk/readme.txt

    r2090705 r2315109  
    33Tags: WooCommerce, E-commerce, product, sale date product, sale date product list, product list, sale date product tag, sale date product info, WooCommerce product
    44Requires at least: 4.0
    5 Tested up to: 5.2
     5Tested up to: 5.4
    66Requires PHP : 5.4
    7 Stable tag: 1.0.8
     7Stable tag: 1.0.9
    88License: GPLv2 or later
    99
    10 Display a customizable sale end date tag for WooCommerce products.
     10Display a customizable sale date tag for WooCommerce products.
    1111
    1212
     
    2626This plugin is fully free ; no hidden features, no premium features, no ads, no account creation... Just a **free plugin made with love by Motpr355**.
    2727
    28 This plugin allow you to display a customizable  customizable sale end date tag for WooCommerce products.
     28This plugin allow you to display a customizable sale date tag for WooCommerce products.
    2929
    3030You can customize your tag in the plugin settings.
     
    3434- Choose tag color with a color picker
    3535- Choose font weight between normal and bold
    36 - Choose text transform. Examples: "Until 2018-10-01", "until 2018-10-01", "UNTIL 2018-10-01". Date format is the one defined in WordPress Settings > General.
     36- Choose text transform. Examples: "On sale until 2018-10-01", "ON SALE UNTIL 2018-10-01"... Date format is the one defined in WordPress Settings > General.
     37- Choose if you want to display sale start date, end date, or both
    3738- Preview the tag before save configuration
    3839
     
    6061== Changelog ==
    6162
     63= 1.0.9 =
     64* Display product sale start date option
     65* Translations update
     66
    6267= 1.0.7 =
    6368* Translations update
  • woo-sale-product-date-info/trunk/woo-sale-product-date-info.php

    r2090705 r2315109  
    22/*
    33Plugin Name: WooCommerce sale product date info
    4 Description: Display a customizable sale end date tag for WooCommerce products.
    5 Version: 1.0.8
     4Description: Display a customizable sale date tag for WooCommerce products.
     5Version: 1.0.9
    66Author: Motpr355
    77Text Domain: woo-sale-product-date-info
     
    1818    private $font_weight_enum;
    1919    private $text_transform_enum;
     20    private $display_enum;
    2021
    2122    public function __construct() {
     
    5354
    5455    private function init_data() {
    55         $this->configuration_saved = false;
    56         $this->settings = $this->get_settings();
    5756        $this->settings_enum = ( object ) array(
    5857            'nonce' => 'nonce',
     
    6160            'color' => 'color',
    6261            'font_weight' => 'font_weight',
    63             'text_transform' => 'text_transform'
     62            'text_transform' => 'text_transform',
     63            'display' => 'display'
    6464        );
    6565        $this->activation_enum = ( object ) array(
     
    7676            'uppercase' => 'uppercase'
    7777        );
     78        $this->display_enum = ( object ) array(
     79            'start_date' => 'start_date',
     80            'end_date' => 'end_date',
     81            'start_end_date' => 'start_end_date'
     82        );
     83
     84        $this->configuration_saved = false;
     85        $this->settings = $this->get_settings();
    7886    }
    7987
     
    96104            $this->settings->{$this->settings_enum->color},
    97105            $this->settings->{$this->settings_enum->font_weight},
    98             $this->settings->{$this->settings_enum->text_transform} ) ) {
     106            $this->settings->{$this->settings_enum->text_transform},
     107            $this->settings->{$this->settings_enum->display} ) ) {
    99108            include plugin_dir_path( __FILE__ ) . 'css/website.php';
    100         }   
     109        }
    101110    }
    102111
     
    106115            if ( $product->is_on_sale() ) {
    107116                if ( function_exists( 'get_post_meta' ) && function_exists( 'get_the_ID' ) && function_exists( 'date_i18n' ) ) {
    108                     $date = get_post_meta( get_the_ID(), '_sale_price_dates_to', true );
    109                     if ( $date && is_string( $date ) ) {
    110                             $date = date_i18n( get_option( 'date_format' ), $date );
    111                         if ( isset ( $this->display_info_content ) ) {
    112                             return str_replace( '%s', $date, $this->display_info_content );
    113                         }
    114                         if ( function_exists( 'ob_start' ) && function_exists( 'ob_get_clean' ) ) {
    115                             ob_start();
    116                             include plugin_dir_path( __FILE__ ) . 'html/website.php';
    117                             $this->display_info_content = ob_get_clean();
    118                             return str_replace( '%s', $date, $this->display_info_content );
     117                    $date_format = get_option( 'date_format' );
     118                    if ( $date_format !== false ) {
     119                        if ( method_exists( $product, 'get_date_on_sale_from' ) && method_exists( $product, 'get_date_on_sale_to' ) ) {
     120                            $begin_date_display = false;
     121                            $begin_date = $product->get_date_on_sale_from( 'edit' );
     122                            if ( $begin_date && method_exists( $begin_date, 'getOffsetTimestamp' ) ) {
     123                                $begin_date_display = date_i18n( $date_format, $begin_date->getOffsetTimestamp() );
     124                            }
     125                            $end_date_display = false;
     126                            $end_date = $product->get_date_on_sale_to( 'edit' );
     127                            if ( $end_date && method_exists( $end_date, 'getOffsetTimestamp' ) ) {
     128                                $end_date_display = date_i18n( $date_format, $end_date->getOffsetTimestamp() );
     129                            }
     130                            if ( $begin_date_display || $end_date_display ) {
     131                                if ( isset ( $this->settings->{$this->settings_enum->background_color},
     132                                    $this->settings->{$this->settings_enum->color},
     133                                    $this->settings->{$this->settings_enum->font_weight},
     134                                    $this->settings->{$this->settings_enum->text_transform},
     135                                    $this->settings->{$this->settings_enum->display}) ) {
     136                                    $display_option = $this->settings->{$this->settings_enum->display};
     137                                    $text = false;
     138                                    if ( $begin_date_display && $end_date_display ) {
     139                                        if ( $display_option === $this->display_enum->start_date ) {
     140                                            $text = sprintf( __( 'On sale from %s', 'woo-sale-product-date-info' ), $begin_date_display );
     141                                        } else if ( $display_option === $this->display_enum->end_date ) {
     142                                            $text = sprintf( __( 'On sale until %s', 'woo-sale-product-date-info' ), $end_date_display );
     143                                        } else if ( $display_option === $this->display_enum->start_end_date ) {
     144                                            $text = sprintf( __( 'On sale from %s to %s', 'woo-sale-product-date-info' ), $begin_date_display, $end_date_display );
     145                                        }
     146                                    } else if ( $begin_date_display && ! $end_date_display ) {
     147                                        if ( $display_option === $this->display_enum->start_date || $display_option === $this->display_enum->start_end_date ) {
     148                                            $text = sprintf( __( 'On sale from %s', 'woo-sale-product-date-info' ), $begin_date_display );
     149                                        }
     150                                    } else if ( ! $begin_date_display && $end_date_display ) {
     151                                        if ( $display_option === $this->display_enum->end_date || $display_option === $this->display_enum->start_end_date ) {
     152                                            $text = sprintf( __( 'On sale until %s', 'woo-sale-product-date-info' ), $end_date_display );
     153                                        }
     154                                    }
     155                                    if ( $text !== false ) {
     156                                        if ( isset ( $this->display_info_content ) ) {
     157                                            return str_replace( 'CONTENT', $text, $this->display_info_content );
     158                                        }
     159                                        if ( function_exists( 'ob_start' ) && function_exists( 'ob_get_clean' ) ) {
     160                                            ob_start();
     161                                            include plugin_dir_path( __FILE__ ) . 'html/website.php';
     162                                            $this->display_info_content = ob_get_clean();
     163                                            return str_replace( 'CONTENT', $text, $this->display_info_content );
     164                                        }
     165                                    }
     166                                }
     167                            }
    119168                        }
    120169                    }
     
    143192            'color' => '#ffffff',
    144193            'font_weight' => 'bold',
    145             'text_transform' => 'none'
     194            'text_transform' => 'none',
     195            'display' => 'end_date'
    146196        );
    147197        update_option( 'motpr355_woo_sale_product_date_info_settings', $settings );
     
    149199
    150200    public function installed( $plugin ) {
    151         if( $plugin === plugin_basename( __FILE__ ) ) {
    152         exit( wp_redirect( admin_url( 'edit.php?post_type=product&page=motpr355_woo_sale_product_date_info' ) ) );
    153         }
     201        if( $plugin === plugin_basename( __FILE__ ) && is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
     202            exit( wp_redirect( admin_url( 'edit.php?post_type=product&page=motpr355_woo_sale_product_date_info' ) ) );
     203        }
    154204    }
    155205
     
    201251                    plugins_url( 'js/admin.js', __FILE__ ),
    202252                    array( 'wp-color-picker' ),
    203                     '1.0.0',
     253                    '1.0.9',
    204254                    true
    205255                );
     
    214264                    plugins_url( 'js/admin-extensions.js', __FILE__ ),
    215265                    array(),
    216                     '1.0.0',
     266                    '1.0.9',
    217267                    true
    218268                );
     
    221271                    'motpr355_woo_sale_product_date_info_translations',
    222272                    array(
    223                         'woo_inactive' => __( 
     273                        'woo_inactive' => __(
    224274                            'WooCommerce must be actived',
    225275                            'woo-sale-product-date-info'
     
    242292                plugins_url( 'css/admin.css', __FILE__ ),
    243293                array(),
    244                 '1.0.0'
     294                '1.0.9'
    245295            );
    246296            wp_enqueue_style( 'motpr355_woo_sale_product_date_info_style' );
     
    268318    private function save_configuration() {
    269319        if ( isset ( $_POST[ 'nonce' ], $_POST[ 'activation' ], $_POST[ 'background_color' ],
    270             $_POST[ 'color' ], $_POST[ 'font_weight' ], $_POST[ 'text_transform' ] ) ) {
     320            $_POST[ 'color' ], $_POST[ 'font_weight' ], $_POST[ 'text_transform' ], $_POST[ 'display' ] ) ) {
    271321            $nonce = $this->get_cleaned_posted_data( $_POST[ 'nonce' ] );
    272322            $saved_nonce = $this->settings->{$this->settings_enum->nonce};
     
    277327                $font_weight = $this->get_cleaned_font_weight( $_POST[ 'font_weight' ] );
    278328                $text_transform = $this->get_cleaned_text_transform( $_POST[ 'text_transform' ] );
     329                $display = $this->get_cleaned_display( $_POST[ 'display' ] );
    279330                if ( $activation !== false && $background_color !== false && $color !== false
    280                     && $font_weight !== false && $text_transform !== false ) {
     331                    && $font_weight !== false && $text_transform !== false && $display !== false ) {
    281332                    $settings = array(
    282333                        'nonce' => $saved_nonce,
     
    285336                        'color' => $color,
    286337                        'font_weight' => $font_weight,
    287                         'text_transform' => $text_transform
     338                        'text_transform' => $text_transform,
     339                        'display' => $display
    288340                    );
    289341                    update_option( 'motpr355_woo_sale_product_date_info_settings', $settings );
     
    320372    }
    321373
     374    private function get_cleaned_display( $display ) {
     375        $display = $this->get_cleaned_posted_data( $display );
     376        return in_array( $display, ( array ) $this->display_enum ) ? $display : false;
     377    }
     378
    322379    private function get_cleaned_posted_data( $data ) {
    323380        return stripslashes_deep( sanitize_text_field( $data ) );
     
    337394
    338395    private function get_settings() {
    339         return ( object ) get_option( 'motpr355_woo_sale_product_date_info_settings', array() );
     396        $settings = ( object ) get_option( 'motpr355_woo_sale_product_date_info_settings', array() );
     397        if ( ! isset ( $settings->display ) ) {
     398            $settings->display = $this->display_enum->end_date;
     399        }
     400        return $settings;
    340401    }
    341402
Note: See TracChangeset for help on using the changeset viewer.