Plugin Directory

Changeset 1584189


Ignore:
Timestamp:
01/28/2017 02:43:00 PM (8 years ago)
Author:
KillBill-sbor
Message:

Version 1.0 Release

Location:
featured-first-then-random-sorting-for-woocommerce/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • featured-first-then-random-sorting-for-woocommerce/trunk/i18n/languages/woocommerce-featured-then-random-sorting-ru_RU.po

    r1560860 r1584189  
    22msgstr ""
    33"Project-Id-Version: WooCommerce Featured First then Random Sorting Option\n"
    4 "POT-Creation-Date: 2016-11-02 19:16+0300\n"
    5 "PO-Revision-Date: 2016-11-02 19:22+0300\n"
     4"POT-Creation-Date: 2017-01-22 22:28+0300\n"
     5"PO-Revision-Date: 2017-01-22 22:30+0300\n"
     6"Last-Translator: \n"
    67"Language-Team: [email protected]\n"
     8"Language: ru\n"
    79"MIME-Version: 1.0\n"
    810"Content-Type: text/plain; charset=UTF-8\n"
     
    1416"X-Poedit-KeywordsList: __;_e;_n:1,2;esc_attr__;esc_attr_e;esc_html__;"
    1517"esc_html_e\n"
    16 "Last-Translator: \n"
    17 "Language: ru\n"
    1818"X-Poedit-SearchPath-0: .\n"
    1919
    20 #: woocommerce-featured-then-random-sorting.php:85
     20#: woocommerce-featured-then-random-sorting.php:109
    2121#, php-format
    2222msgid "You cannot clone instances of %s."
    2323msgstr "Вы не можете клонировать экземпляры %s."
    2424
    25 #: woocommerce-featured-then-random-sorting.php:90
     25#: woocommerce-featured-then-random-sorting.php:114
    2626#, php-format
    2727msgid "You cannot unserialize instances of %s."
    2828msgstr "Вы не можете десериализировать экземпляры %s."
    2929
    30 #: woocommerce-featured-then-random-sorting.php:96
     30#: woocommerce-featured-then-random-sorting.php:120
    3131msgid "Settings"
    3232msgstr "Настройки"
    3333
    34 #: woocommerce-featured-then-random-sorting.php:97
     34#: woocommerce-featured-then-random-sorting.php:121
    3535msgid "Author"
    3636msgstr "Автор"
    3737
    38 #: woocommerce-featured-then-random-sorting.php:132
     38#: woocommerce-featured-then-random-sorting.php:154
    3939#, php-format
    4040msgid ""
     
    4747"WooCommerce до версии 2.3 или выше%4$s"
    4848
    49 #: woocommerce-featured-then-random-sorting.php:162
     49#: woocommerce-featured-then-random-sorting.php:196
    5050msgid "Custom Default Sorting Label"
    5151msgstr "Название сортировки по умолчанию"
    5252
    53 #: woocommerce-featured-then-random-sorting.php:166
     53#: woocommerce-featured-then-random-sorting.php:201
    5454msgid ""
    5555"You can change Default sorting label to any other, for example, ""
    56 "Our Sorting""
     56"Our Sorting" (or leave blank)"
    5757msgstr ""
    58 "Вы можете изменить название сортировки по умолчанию на "
    59 "любое другое, например, “Наша сортировка”"
     58"Вы можете изменить название сортировки по умолчанию, например, "
     59"на “Наша сортировка” (или оставьте поле пустым)"
    6060
    61 #: woocommerce-featured-then-random-sorting.php:169
     61#: woocommerce-featured-then-random-sorting.php:204
    6262msgid "Custom Featured First then Random Sorting Label"
    6363msgstr "Название сортировки \"Сначала рекомендуемые, затем случайно\""
    6464
    65 #: woocommerce-featured-then-random-sorting.php:173
     65#: woocommerce-featured-then-random-sorting.php:209
    6666msgid ""
    6767"You can change Featured First then Random Sorting label to any other, "
     
    6969msgstr ""
    7070"Вы можете изменить название сортировки “Сначала рекомендуемые, "
    71 "затем случайно” на любое другое, например, “Лучшая "
    72 "сортировка в мире”"
     71"затем случайно” на любую другую, например, “Лучшая "
     72"сортировка в мире!”"
    7373
    74 #: woocommerce-featured-then-random-sorting.php:197
     74#: woocommerce-featured-then-random-sorting.php:212
     75msgid "Randomize..."
     76msgstr "Перемешивать товары..."
     77
     78#: woocommerce-featured-then-random-sorting.php:217
     79msgid "On the first archive page (default)"
     80msgstr "На первой странице каталога (по умолчанию)"
     81
     82#: woocommerce-featured-then-random-sorting.php:218
     83msgid "Every day"
     84msgstr "Каждый день"
     85
     86#: woocommerce-featured-then-random-sorting.php:219
     87msgid "Every hour"
     88msgstr "Каждый час"
     89
     90#: woocommerce-featured-then-random-sorting.php:222
     91msgid ""
     92"Choose an event when order should be randomized. Timer starts when "
     93"user opens your catalog"
     94msgstr ""
     95"Выберите событие, при котором товары должны перемешиваться. Отсчёт времени "
     96"начинается с момента, когда пользователь открывает каталог"
     97
     98#: woocommerce-featured-then-random-sorting.php:246
    7599msgid "Default sorting"
    76 msgstr "Исходная сортировка"
     100msgstr "Сортировка по умолчанию"
    77101
    78 #: woocommerce-featured-then-random-sorting.php:203
     102#: woocommerce-featured-then-random-sorting.php:252
    79103msgid "Show featured items first then random"
    80 msgstr "Сначала рекомендуемые, затем случайно"
     104msgstr "Показывать сначала рекомендуемые, затем случайные товары"
     105
     106#~ msgid ""
     107#~ "You can change Default sorting label to any other, for example, "
     108#~ ""Our Sorting""
     109#~ msgstr ""
     110#~ "Вы можете изменить название сортировки по умолчанию на "
     111#~ "любое другое, например, “Наша сортировка”"
  • featured-first-then-random-sorting-for-woocommerce/trunk/readme.txt

    r1560860 r1584189  
    1 === Featured First then Random sorting for WooCommerce ===
     1=== Featured First then Random for WooCommerce ===
    22Contributors: killbill-sbor
    33Tags: woocommerce, sorting, random, featured
     
    1919
    2020* This plugin uses Session seed (unique session id) to randomize item order so you can use random product list even with pagination!
    21 * It is automatically reset when user opens the first page.
     21* It is automatically reset when user opens the first page or by timer (every hour/day. Timer starts when user opens your store).
    2222* Demo web-site is available [here](http://toryjoy.ru/shop/?orderby=featured_first_then_random).
    2323
     
    3232Also you can customize the plugin:
    33331. Go to Dashboard &rarr; WooCommerce &rarr; Settings &rarr; Items &rarr; Display<br>
    34 1. Here you can choose default sorting option, default sorting label and Featured First then Random custom label.
     341. Here you can choose default sorting option, default sorting label, randomize event and Featured First then Random custom label.
    3535
    3636== Frequently Asked Questions ==
     
    5656
    5757= 1.0 =
    58 * Initial version
     58* Added capability to change randomize event (hourly, daily or on the first page)
     59* Improved styling of settings page
     60* Code improvements
     61* New logo
     62
     63= 0.9 =
     64* Initial release
  • featured-first-then-random-sorting-for-woocommerce/trunk/woocommerce-featured-then-random-sorting.php

    r1560860 r1584189  
    66 * Author: Vitalii Rizo
    77 * Author URI: http://squirrel-research.ru
    8  * Version: 0.9
     8 * Version: 1.0
    99 * Text Domain: woocommerce-featured-then-random-sorting
    1010 *
     
    2020
    2121// Check if WooCommerce is active
    22 if ( ! wc_featured_than_random_sorting_options::is_woocommerce_active() ) {
    23   return;
     22if ( !wc_featured_than_random_sorting_options::is_woocommerce_active() ) {
     23    return;
    2424}
    2525
    2626// WC version check
    2727if ( version_compare( get_option( 'woocommerce_db_version' ), '2.3.0', '<' ) ) {
    28   add_action( 'admin_notices', wc_featured_than_random_sorting_options::render_outdated_wc_version_notice() );
    29   return;
     28    add_action( 'admin_notices', wc_featured_than_random_sorting_options::render_outdated_wc_version_notice() );
     29    return;
    3030}
    3131
    3232// Init plugin after all other plugins loaded:
    3333function init_wc_featured_than_random_sorting_options() {
    34   wc_featured_than_random_sorting_options();
     34    wc_featured_than_random_sorting_options();
    3535}
    3636add_action( 'plugins_loaded', 'init_wc_featured_than_random_sorting_options' );
     
    3838
    3939class wc_featured_than_random_sorting_options {
    40   // Current plugin version:
    41   const VERSION = '0.9.0';
    42 
    43   // @var wc_featured_than_random_sorting_options single instance of this plugin
    44   protected static $instance;
    45 
    46   public function __construct() {
    47     // modify product sorting settings
    48     add_filter( 'woocommerce_catalog_orderby', array( $this, 'modify_sorting_settings' ) );
    49 
    50     // add new sorting options to orderby dropdown
    51     add_filter( 'woocommerce_default_catalog_orderby_options', array( $this, 'modify_sorting_settings' ) );
    52 
    53     // add new product sorting arguments
    54     add_filter( 'woocommerce_get_catalog_ordering_args', array( $this, 'add_new_shop_ordering_args' ) );
    55 
    56     // load translations
    57     add_action( 'init', array( $this, 'load_translation' ) );
    58 
    59     // Add settings and links in admin panel:
    60     if ( is_admin() && ! is_ajax() ) {
    61         // add settings
    62         add_filter( 'woocommerce_product_settings', array( $this, 'add_settings' ) );
    63 
    64         // add plugin links
    65         add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_plugin_links' ) );
    66     }
    67   }
    68 
    69 
    70 
    71   // Ensures only one instance is/can be loaded
    72   public static function instance() {
    73     if ( is_null( self::$instance ) ) {
    74       self::$instance = new self();
    75     }
    76     return self::$instance;
    77   }
    78  
    79  
    80   /**
    81    * Singleton pattern: prevent creating more instances by clone and unserialize:
    82    */
    83   public function __clone() {
    84       /* translators: Placeholders: %s - plugin name */
    85       _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'You cannot clone instances of %s.', 'woocommerce-featured-then-random-sorting' ), 'WooCommerce Extra Product Sorting Options' ), '2.4.0' );
    86   }
    87 
    88   public function __wakeup() {
    89       /* translators: Placeholders: %s - plugin name */
    90       _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'You cannot unserialize instances of %s.', 'woocommerce-featured-then-random-sorting' ), 'WooCommerce Extra Product Sorting Options' ), '2.4.0' );
    91   }
    92 
    93   // Add plugin links: Settings and Author web site:
    94   public function add_plugin_links( $links ) {
    95       $plugin_links = array(
    96           '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=products&section=display' ) . '">' . __( 'Settings', 'woocommerce-featured-then-random-sorting' ) . '</a>',
    97           '<a href="http://squirrel-research.ru/" target="_blank">' . __( 'Author', 'woocommerce-featured-then-random-sorting' ) . '</a>',
    98       );
    99       return array_merge( $plugin_links, $links );
    100   }
    101 
    102 
    103 
    104   /**
    105    * Load Translations
    106    */
    107   public function load_translation() {
    108       load_plugin_textdomain( 'woocommerce-featured-then-random-sorting', false, dirname( plugin_basename( __FILE__ ) ) . '/i18n/languages' );
    109   }
    110 
    111 
    112   /**
    113    * Checks if WooCommerce is active
    114    */
    115   public static function is_woocommerce_active() {
    116       $active_plugins = (array) get_option( 'active_plugins', array() );
    117 
    118       if ( is_multisite() ) {
    119           $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
    120       }
    121 
    122       return in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
    123   }
    124 
    125 
    126   /**
    127    * Renders a notice when WooCommerce version is outdated
    128    */
    129   public static function render_outdated_wc_version_notice() {
    130     $message = sprintf(
    131       /* translators: %1$s and %2$s are <strong> tags. %3$s and %4$s are <a> tags */
    132       esc_html__( '%1$sWooCommerce Featured first then Random plugin is inactive.%2$s This plugin requires WooCommerce 2.3 or newer. Please %3$supdate WooCommerce to version 2.3 or newer%4$s', 'woocommerce-featured-then-random-sorting' ),
    133       '<strong>',
    134       '</strong>',
    135       '<a href="' . admin_url( 'plugins.php' ) . '">',
    136       '&nbsp;&raquo;</a>'
    137     );
    138 
    139     printf( '<div class="error"><p>%s</p></div>', $message );
    140   }
    141 
    142 
    143   /********************/
    144   /** Plugin methods **/
    145   /********************/
    146 
    147   /**
    148    * Add Settings to WooCommerce Settings > Products page after "Default Product Sorting" setting
    149    */
    150   public function add_settings( $settings ) {
    151 
    152     $updated_settings = array();
    153 
    154     foreach ( $settings as $setting ) {
    155 
    156       $updated_settings[] = $setting;
    157 
    158       if ( isset( $setting['id'] ) && 'woocommerce_default_catalog_orderby' === $setting['id'] ) {
    159 
    160         $new_settings = array(
    161           array(
    162             'title'    => __( 'Custom Default Sorting Label', 'woocommerce-featured-then-random-sorting' ),
    163             'id'       => 'wc_custom_default_sorting_name',
    164             'type'     => 'text',
    165             'default'  => '',
    166             'desc_tip' => __( 'You can change Default sorting label to any other, for&nbsp;example, &quot;Our Sorting&quot;', 'woocommerce-featured-then-random-sorting' ),
    167           ),
    168           array(
    169             'title'    => __( 'Custom Featured First then Random Sorting Label', 'woocommerce-featured-then-random-sorting' ),
    170             'id'       => 'wc_rename_featured_than_random_sorting',
    171             'type'     => 'text',
    172             'default'  => '',
    173             'desc_tip' => __( 'You can change Featured First then Random Sorting label to any other, for&nbsp;example, &quot;Best Sorting Ever&quot;', 'woocommerce-featured-then-random-sorting' ),
    174           ),
    175         );
    176 
    177         $updated_settings = array_merge( $updated_settings, $new_settings );
    178 
    179       }
    180     }
    181 
    182     return $updated_settings;
    183   }
    184 
    185 
     40    // Current plugin version:
     41    const VERSION = '1.0.0';
     42   
     43    // @var wc_featured_than_random_sorting_options single instance of this plugin
     44    protected static $instance;
     45   
     46    public function __construct() {
     47        // modify product sorting settings
     48        add_filter( 'woocommerce_catalog_orderby', array(
     49            $this,
     50            'modify_sorting_settings'
     51        ) );
     52       
     53        // add new sorting options to orderby dropdown
     54        add_filter( 'woocommerce_default_catalog_orderby_options', array(
     55            $this,
     56            'modify_sorting_settings'
     57        ) );
     58       
     59        // add new product sorting arguments
     60        add_filter( 'woocommerce_get_catalog_ordering_args', array(
     61            $this,
     62            'add_new_shop_ordering_args'
     63        ) );
     64       
     65        // load translations
     66        add_action( 'init', array(
     67            $this,
     68            'load_translation'
     69        ) );
     70       
     71        // Add settings and links in admin panel:
     72        if ( is_admin() && !is_ajax() ) {
     73            // add settings
     74            add_filter( 'woocommerce_product_settings', array(
     75                $this,
     76                'add_settings'
     77            ) );
     78           
     79            // add plugin links
     80            add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array(
     81                $this,
     82                'add_plugin_links'
     83            ) );
     84           
     85            // add styling
     86            add_action( 'admin_head', array(
     87                $this,
     88                'featured_first_styling'
     89            ) );
     90        }
     91    }
     92   
     93   
     94   
     95    // Ensures only one instance is/can be loaded
     96    public static function instance() {
     97        if ( is_null( self::$instance ) ) {
     98            self::$instance = new self();
     99        }
     100        return self::$instance;
     101    }
     102   
     103   
     104    /**
     105     * Singleton pattern: prevent creating more instances by clone and unserialize:
     106     */
     107    public function __clone() {
     108        /* translators: Placeholders: %s - plugin name */
     109        _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'You cannot clone instances of %s.', 'woocommerce-featured-then-random-sorting' ), 'WooCommerce Extra Product Sorting Options' ), '2.4.0' );
     110    }
     111   
     112    public function __wakeup() {
     113        /* translators: Placeholders: %s - plugin name */
     114        _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'You cannot unserialize instances of %s.', 'woocommerce-featured-then-random-sorting' ), 'WooCommerce Extra Product Sorting Options' ), '2.4.0' );
     115    }
     116   
     117    // Add plugin links: Settings and Author web site:
     118    public function add_plugin_links( $links ) {
     119        $plugin_links = array(
     120            '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=products&section=display' ) . '">' . __( 'Settings', 'woocommerce-featured-then-random-sorting' ) . '</a>',
     121            '<a href="http://squirrel-research.ru/" target="_blank">' . __( 'Author', 'woocommerce-featured-then-random-sorting' ) . '</a>'
     122        );
     123        return array_merge( $plugin_links, $links );
     124    }
     125   
     126   
     127   
     128    /**
     129     * Load Translations
     130     */
     131    public function load_translation() {
     132        load_plugin_textdomain( 'woocommerce-featured-then-random-sorting', false, dirname( plugin_basename( __FILE__ ) ) . '/i18n/languages' );
     133    }
     134   
     135   
     136    /**
     137     * Checks if WooCommerce is active
     138     */
     139    public static function is_woocommerce_active() {
     140        $active_plugins = (array) get_option( 'active_plugins', array ());
     141       
     142        if ( is_multisite() ) {
     143            $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array ()) );
     144        }
     145       
     146        return in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
     147    }
     148   
     149   
     150    /**
     151     * Renders a notice when WooCommerce version is outdated
     152     */
     153    public static function render_outdated_wc_version_notice() {
     154        $message = sprintf( /* translators: %1$s and %2$s are <strong> tags. %3$s and %4$s are <a> tags */ esc_html__( '%1$sWooCommerce Featured first then Random plugin is inactive.%2$s This plugin requires WooCommerce 2.3 or newer. Please %3$supdate WooCommerce to version 2.3 or newer%4$s', 'woocommerce-featured-then-random-sorting' ), '<strong>', '</strong>', '<a href="' . admin_url( 'plugins.php' ) . '">', '&nbsp;&raquo;</a>' );
     155       
     156        printf( '<div class="error"><p>%s</p></div>', $message );
     157    }
     158   
     159    /**
     160     * Additional styling in Admin Dashboard
     161     */
     162    public function featured_first_styling() {
     163        echo '
     164            <style>
     165                .featured-first-input-class {
     166                    padding-top: 5px;
     167                    padding-bottom: 5px;
     168                    border-radius: 3px;
     169                    margin-left: 0;
     170                    max-width: 350px;
     171                    width: 100%;
     172                }
     173            </style>';
     174    }
     175   
     176    /********************/
     177    /** Plugin methods **/
     178    /********************/
     179   
     180    /**
     181     * Add Settings to WooCommerce Settings > Products page after "Default Product Sorting" setting
     182     * Details: https://docs.woocommerce.com/document/settings-api/
     183     */
     184    public function add_settings( $settings ) {
     185       
     186        $updated_settings = array();
     187       
     188        foreach ( $settings as $setting ) {
     189           
     190            $updated_settings[] = $setting;
     191           
     192            if ( isset( $setting['id'] ) && 'woocommerce_default_catalog_orderby' === $setting['id'] ) {
     193               
     194                $new_settings = array(
     195                     array(
     196                        'title' => __( 'Custom Default Sorting Label', 'woocommerce-featured-then-random-sorting' ),
     197                        'id' => 'wc_custom_default_sorting_name',
     198                        'class' => 'featured-first-input-class',
     199                        'type' => 'text',
     200                        'default' => '',
     201                        'desc_tip' => __( 'You can change Default sorting label to any other, for&nbsp;example, &quot;Our Sorting&quot; (or&nbsp;leave blank)', 'woocommerce-featured-then-random-sorting' )
     202                    ),
     203                    array(
     204                        'title' => __( 'Custom Featured First then Random Sorting Label', 'woocommerce-featured-then-random-sorting' ),
     205                        'id' => 'wc_rename_featured_than_random_sorting',
     206                        'class' => 'featured-first-input-class',
     207                        'type' => 'text',
     208                        'default' => '',
     209                        'desc_tip' => __( 'You can change Featured First then Random Sorting label to any other, for&nbsp;example, &quot;Best Sorting Ever&quot;', 'woocommerce-featured-then-random-sorting' )
     210                    ),
     211                    array(
     212                        'title' => __( 'Randomize...', 'woocommerce-featured-then-random-sorting' ),
     213                        'class' => 'featured-first-input-class',
     214                        'id' => 'wc_randomize_sorting',
     215                        'type' => 'select',
     216                        'options' => array(
     217                            null => __( 'On the first archive page (default)', 'woocommerce-featured-then-random-sorting' ),
     218                            86400 => __( 'Every day', 'woocommerce-featured-then-random-sorting' ),
     219                            3600 => __( 'Every hour', 'woocommerce-featured-then-random-sorting' )
     220                        ),
     221                        'default' => null,
     222                        'desc_tip' => __( 'Choose an&nbsp;event when order should be&nbsp;randomized. Timer starts when user opens your catalog', 'woocommerce-featured-then-random-sorting' )
     223                    )
     224                );
     225               
     226                $updated_settings = array_merge( $updated_settings, $new_settings );
     227               
     228            }
     229        }
     230       
     231        return $updated_settings;
     232    }
     233   
     234   
    186235    /**
    187236     * Change "Default Sorting" to custom name and add new sorting options.
    188   * It is added to admin + frontend dropdown.
     237    * It is added to admin + frontend dropdown.
    189238     */
    190239    public function modify_sorting_settings( $sortby ) {
    191    
    192     // Get custom sorting labels if they are exist:
    193         $new_default_name = get_option( 'wc_custom_default_sorting_name' );
     240       
     241        // Get custom sorting labels if they are exist:
     242        $new_default_name              = get_option( 'wc_custom_default_sorting_name' );
    194243        $new_featured_than_random_name = get_option( 'wc_rename_featured_than_random_sorting' );
    195 
     244       
    196245        if ( $new_default_name ) {
    197             $sortby = str_replace( __("Default sorting", 'woocommerce'), $new_default_name, $sortby );
    198         }
    199    
     246            $sortby = str_replace( __( "Default sorting", 'woocommerce' ), $new_default_name, $sortby );
     247        }
     248       
    200249        if ( $new_featured_than_random_name ) {
    201       $sortby['featured_first_then_random'] = $new_featured_than_random_name;
     250            $sortby['featured_first_then_random'] = $new_featured_than_random_name;
    202251        } else {
    203       $sortby['featured_first_then_random'] = __( 'Show featured items first then random', 'woocommerce-featured-then-random-sorting' );
    204     }
    205 
     252            $sortby['featured_first_then_random'] = __( 'Show featured items first then random', 'woocommerce-featured-then-random-sorting' );
     253        }
     254       
    206255        return $sortby;
    207256    }
    208 
    209 
     257   
     258   
    210259    /**
    211260     * Add sorting option to WC sorting arguments
    212261     */
    213262    public function add_new_shop_ordering_args( $sort_args ) {
    214 
     263       
    215264        // If we have the orderby via URL, let's pass it in
    216265        // This means we're on a shop / archive, so if we don't have it, use the default
     
    220269            $orderby_value = apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
    221270        }
    222 
     271       
    223272        // Since a shortcode can be used on a non-WC page, we won't have $_GET['orderby']
    224273        // Grab it from the passed in sorting args instead for non-WC pages
    225274        // Don't use this on WC pages since it breaks the default
    226         if ( ! is_woocommerce() && isset( $sort_args['orderby'] ) ) {
     275        if ( !is_woocommerce() && isset( $sort_args['orderby'] ) ) {
    227276            $orderby_value = $sort_args['orderby'];
    228277        }
    229 
    230         $fallback = apply_filters( 'wc_featured_than_random_sorting_options_fallback', 'title', $orderby_value );
     278       
     279        $fallback       = apply_filters( 'wc_featured_than_random_sorting_options_fallback', 'title', $orderby_value );
    231280        $fallback_order = apply_filters( 'wc_featured_than_random_sorting_options_fallback_order', 'ASC', $orderby_value );
    232 
    233         switch( $orderby_value ) {
    234 
     281       
     282        switch ( $orderby_value ) {
     283           
    235284            case 'featured_first_then_random':
    236    
    237         session_start();
    238 
    239         // Reset seed on load of initial archive page
    240         if( ! get_query_var( 'paged' ) || get_query_var( 'paged' ) == 0 || get_query_var( 'paged' ) == 1 ) {
    241             if( isset( $_SESSION['seed'] ) ) {
    242                 unset( $_SESSION['seed'] );
    243             }
    244         }
    245 
    246         // Get seed from session variable if it exists
    247         $seed = false;
    248         if( isset( $_SESSION['seed'] ) ) {
    249             $seed = $_SESSION['seed'];
    250         }
    251 
    252         // Set new seed if none exists
    253         if ( ! $seed ) {
    254             $seed = rand();
    255             $_SESSION['seed'] = $seed;
    256         }
    257 
    258         // Order by two parameters: meta key and random.
    259         $sort_args['orderby']  = array( 'meta_value' => 'DESC', 'rand('. $seed .')' => 'ASC', $fallback => $fallback_order );
    260         $sort_args['meta_key'] = '_featured';
    261      
    262       // I'm going to add more sorting options later so that I use switch/case construction
    263        
    264             break;
    265 
    266         }
    267 
     285               
     286                session_start();
     287               
     288                // When it's necessary to randomize?
     289                $randomize_every = get_option( 'wc_randomize_sorting' );
     290               
     291                if ( null == $randomize_every ) {
     292                    // Randomize on the first (initial) archive page
     293                    if ( !get_query_var( 'paged' ) || get_query_var( 'paged' ) == 0 || get_query_var( 'paged' ) == 1 ) {
     294                        if ( isset( $_SESSION['seed'] ) ) {
     295                            unset( $_SESSION['seed'] );
     296                        }
     297                    }
     298                   
     299                } else {
     300                    // Check if timestamp exists already
     301                    if ( isset( $_SESSION['date'] ) ) {
     302                        // If exist then compare with current timestamp:
     303                        $time_difference = time() - $_SESSION['date'];
     304                       
     305                        if ( $time_difference > $randomize_every ) {
     306                            // If session is too old then randomize!
     307                            if ( isset( $_SESSION['seed'] ) ) {
     308                                unset( $_SESSION['seed'] );
     309                                $_SESSION['date'] = time();
     310                            }
     311                        }
     312                       
     313                    } else {
     314                        // If timestamp doesn't exist then set current time:
     315                        $_SESSION['date'] = time();
     316                    }
     317                }
     318               
     319                // Get seed from session variable if it exists
     320                $seed = false;
     321                if ( isset( $_SESSION['seed'] ) ) {
     322                    $seed = $_SESSION['seed'];
     323                }
     324               
     325                // Set new seed if none exists
     326                if ( !$seed ) {
     327                    $seed             = rand();
     328                    $_SESSION['seed'] = $seed;
     329                }
     330               
     331                // Order by two parameters: meta key and random.
     332                $sort_args['orderby']  = array(
     333                     'meta_value' => 'DESC',
     334                    'rand(' . $seed . ')' => 'ASC',
     335                    $fallback => $fallback_order
     336                );
     337                $sort_args['meta_key'] = '_featured';
     338               
     339                // I'm going to add more sorting options later so that I use switch/case construction
     340                break;
     341               
     342        }
     343       
    268344        return $sort_args;
    269345    }
     
    275351 */
    276352function wc_featured_than_random_sorting_options() {
    277   return wc_featured_than_random_sorting_options::instance();
     353    return wc_featured_than_random_sorting_options::instance();
    278354}
Note: See TracChangeset for help on using the changeset viewer.