Changeset 1584189
- Timestamp:
- 01/28/2017 02:43:00 PM (8 years ago)
- 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 2 2 msgstr "" 3 3 "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" 6 7 "Language-Team: [email protected]\n" 8 "Language: ru\n" 7 9 "MIME-Version: 1.0\n" 8 10 "Content-Type: text/plain; charset=UTF-8\n" … … 14 16 "X-Poedit-KeywordsList: __;_e;_n:1,2;esc_attr__;esc_attr_e;esc_html__;" 15 17 "esc_html_e\n" 16 "Last-Translator: \n"17 "Language: ru\n"18 18 "X-Poedit-SearchPath-0: .\n" 19 19 20 #: woocommerce-featured-then-random-sorting.php: 8520 #: woocommerce-featured-then-random-sorting.php:109 21 21 #, php-format 22 22 msgid "You cannot clone instances of %s." 23 23 msgstr "Вы не можете клонировать экземпляры %s." 24 24 25 #: woocommerce-featured-then-random-sorting.php: 9025 #: woocommerce-featured-then-random-sorting.php:114 26 26 #, php-format 27 27 msgid "You cannot unserialize instances of %s." 28 28 msgstr "Вы не можете десериализировать экземпляры %s." 29 29 30 #: woocommerce-featured-then-random-sorting.php: 9630 #: woocommerce-featured-then-random-sorting.php:120 31 31 msgid "Settings" 32 32 msgstr "Настройки" 33 33 34 #: woocommerce-featured-then-random-sorting.php: 9734 #: woocommerce-featured-then-random-sorting.php:121 35 35 msgid "Author" 36 36 msgstr "Автор" 37 37 38 #: woocommerce-featured-then-random-sorting.php:1 3238 #: woocommerce-featured-then-random-sorting.php:154 39 39 #, php-format 40 40 msgid "" … … 47 47 "WooCommerce до версии 2.3 или выше%4$s" 48 48 49 #: woocommerce-featured-then-random-sorting.php:1 6249 #: woocommerce-featured-then-random-sorting.php:196 50 50 msgid "Custom Default Sorting Label" 51 51 msgstr "Название сортировки по умолчанию" 52 52 53 #: woocommerce-featured-then-random-sorting.php: 16653 #: woocommerce-featured-then-random-sorting.php:201 54 54 msgid "" 55 55 "You can change Default sorting label to any other, for example, "" 56 "Our Sorting" "56 "Our Sorting" (or leave blank)" 57 57 msgstr "" 58 "Вы можете изменить название сортировки по умолчанию на "59 " любое другое, например, “Наша сортировка”"58 "Вы можете изменить название сортировки по умолчанию, например, " 59 "на “Наша сортировка” (или оставьте поле пустым)" 60 60 61 #: woocommerce-featured-then-random-sorting.php: 16961 #: woocommerce-featured-then-random-sorting.php:204 62 62 msgid "Custom Featured First then Random Sorting Label" 63 63 msgstr "Название сортировки \"Сначала рекомендуемые, затем случайно\"" 64 64 65 #: woocommerce-featured-then-random-sorting.php: 17365 #: woocommerce-featured-then-random-sorting.php:209 66 66 msgid "" 67 67 "You can change Featured First then Random Sorting label to any other, " … … 69 69 msgstr "" 70 70 "Вы можете изменить название сортировки “Сначала рекомендуемые, " 71 "затем случайно” на люб ое другое, например, “Лучшая "72 "сортировка в мире ”"71 "затем случайно” на любую другую, например, “Лучшая " 72 "сортировка в мире!”" 73 73 74 #: woocommerce-featured-then-random-sorting.php:197 74 #: woocommerce-featured-then-random-sorting.php:212 75 msgid "Randomize..." 76 msgstr "Перемешивать товары..." 77 78 #: woocommerce-featured-then-random-sorting.php:217 79 msgid "On the first archive page (default)" 80 msgstr "На первой странице каталога (по умолчанию)" 81 82 #: woocommerce-featured-then-random-sorting.php:218 83 msgid "Every day" 84 msgstr "Каждый день" 85 86 #: woocommerce-featured-then-random-sorting.php:219 87 msgid "Every hour" 88 msgstr "Каждый час" 89 90 #: woocommerce-featured-then-random-sorting.php:222 91 msgid "" 92 "Choose an event when order should be randomized. Timer starts when " 93 "user opens your catalog" 94 msgstr "" 95 "Выберите событие, при котором товары должны перемешиваться. Отсчёт времени " 96 "начинается с момента, когда пользователь открывает каталог" 97 98 #: woocommerce-featured-then-random-sorting.php:246 75 99 msgid "Default sorting" 76 msgstr " Исходная сортировка"100 msgstr "Сортировка по умолчанию" 77 101 78 #: woocommerce-featured-then-random-sorting.php:2 03102 #: woocommerce-featured-then-random-sorting.php:252 79 103 msgid "Show featured items first then random" 80 msgstr "Сначала рекомендуемые, затем случайно" 104 msgstr "Показывать сначала рекомендуемые, затем случайные товары" 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 sortingfor WooCommerce ===1 === Featured First then Random for WooCommerce === 2 2 Contributors: killbill-sbor 3 3 Tags: woocommerce, sorting, random, featured … … 19 19 20 20 * 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). 22 22 * Demo web-site is available [here](http://toryjoy.ru/shop/?orderby=featured_first_then_random). 23 23 … … 32 32 Also you can customize the plugin: 33 33 1. Go to Dashboard → WooCommerce → Settings → Items → Display<br> 34 1. Here you can choose default sorting option, default sorting label and Featured First then Random custom label.34 1. Here you can choose default sorting option, default sorting label, randomize event and Featured First then Random custom label. 35 35 36 36 == Frequently Asked Questions == … … 56 56 57 57 = 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 6 6 * Author: Vitalii Rizo 7 7 * Author URI: http://squirrel-research.ru 8 * Version: 0.98 * Version: 1.0 9 9 * Text Domain: woocommerce-featured-then-random-sorting 10 10 * … … 20 20 21 21 // Check if WooCommerce is active 22 if ( ! 23 22 if ( !wc_featured_than_random_sorting_options::is_woocommerce_active() ) { 23 return; 24 24 } 25 25 26 26 // WC version check 27 27 if ( version_compare( get_option( 'woocommerce_db_version' ), '2.3.0', '<' ) ) { 28 29 28 add_action( 'admin_notices', wc_featured_than_random_sorting_options::render_outdated_wc_version_notice() ); 29 return; 30 30 } 31 31 32 32 // Init plugin after all other plugins loaded: 33 33 function init_wc_featured_than_random_sorting_options() { 34 34 wc_featured_than_random_sorting_options(); 35 35 } 36 36 add_action( 'plugins_loaded', 'init_wc_featured_than_random_sorting_options' ); … … 38 38 39 39 class 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§ion=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 ' »</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 example, "Our Sorting"', '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 example, "Best Sorting Ever"', '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§ion=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' ) . '">', ' »</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 example, "Our Sorting" (or 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 example, "Best Sorting Ever"', '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 event when order should be 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 186 235 /** 187 236 * Change "Default Sorting" to custom name and add new sorting options. 188 237 * It is added to admin + frontend dropdown. 189 238 */ 190 239 public function modify_sorting_settings( $sortby ) { 191 192 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' ); 194 243 $new_featured_than_random_name = get_option( 'wc_rename_featured_than_random_sorting' ); 195 244 196 245 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 200 249 if ( $new_featured_than_random_name ) { 201 250 $sortby['featured_first_then_random'] = $new_featured_than_random_name; 202 251 } else { 203 204 205 252 $sortby['featured_first_then_random'] = __( 'Show featured items first then random', 'woocommerce-featured-then-random-sorting' ); 253 } 254 206 255 return $sortby; 207 256 } 208 209 257 258 210 259 /** 211 260 * Add sorting option to WC sorting arguments 212 261 */ 213 262 public function add_new_shop_ordering_args( $sort_args ) { 214 263 215 264 // If we have the orderby via URL, let's pass it in 216 265 // This means we're on a shop / archive, so if we don't have it, use the default … … 220 269 $orderby_value = apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) ); 221 270 } 222 271 223 272 // Since a shortcode can be used on a non-WC page, we won't have $_GET['orderby'] 224 273 // Grab it from the passed in sorting args instead for non-WC pages 225 274 // Don't use this on WC pages since it breaks the default 226 if ( ! 275 if ( !is_woocommerce() && isset( $sort_args['orderby'] ) ) { 227 276 $orderby_value = $sort_args['orderby']; 228 277 } 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 ); 231 280 $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 235 284 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 268 344 return $sort_args; 269 345 } … … 275 351 */ 276 352 function wc_featured_than_random_sorting_options() { 277 353 return wc_featured_than_random_sorting_options::instance(); 278 354 }
Note: See TracChangeset
for help on using the changeset viewer.