Changeset 3399405
- Timestamp:
- 11/20/2025 05:58:36 AM (4 months ago)
- Location:
- woo-auction
- Files:
-
- 1 added
- 5 edited
-
assets/banner-772x250.png (modified) (previous)
-
trunk/README.md (modified) (1 diff)
-
trunk/admin/class-woo-auction-product-panel.php (modified) (3 diffs)
-
trunk/includes/class-woo-auction-product.php (modified) (4 diffs)
-
trunk/live-auction-for-woocommerce.php (added)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
woo-auction/trunk/README.md
r3388741 r3399405 1 # Woo Live Auctionsby CyberCraft1 # Live Auctions for WooCommerce by CyberCraft 2 2 3 3 ## Brief -
woo-auction/trunk/admin/class-woo-auction-product-panel.php
r3388741 r3399405 242 242 } 243 243 244 // Save auction dates 245 $start_date = isset( $_POST['_auction_start_date'] ) ? sanitize_text_field( wp_unslash( $_POST['_auction_start_date'] ) ) : ''; 246 $end_date = isset( $_POST['_auction_end_date'] ) ? sanitize_text_field( wp_unslash( $_POST['_auction_end_date'] ) ) : ''; 244 // Save auction dates (normalize to site timezone) 245 $start_date_raw = isset( $_POST['_auction_start_date'] ) ? sanitize_text_field( wp_unslash( $_POST['_auction_start_date'] ) ) : ''; 246 $end_date_raw = isset( $_POST['_auction_end_date'] ) ? sanitize_text_field( wp_unslash( $_POST['_auction_end_date'] ) ) : ''; 247 248 $start_date = $this->normalize_datetime_input( $start_date_raw ); 249 $end_date = $this->normalize_datetime_input( $end_date_raw ); 247 250 248 251 update_post_meta( $post_id, '_auction_start_date', $start_date ); … … 263 266 $auction_status = get_post_meta( $post_id, '_auction_status', true ); 264 267 if ( ! $auction_status ) { 265 $current_time = current_time( 'mysql' ); 266 if ( $start_date && strtotime( $start_date ) > strtotime( $current_time ) ) { 268 $current_timestamp = current_time( 'timestamp' ); 269 $start_timestamp = $this->datetime_to_timestamp( $start_date ); 270 $end_timestamp = $this->datetime_to_timestamp( $end_date ); 271 272 if ( $start_timestamp && $start_timestamp > $current_timestamp ) { 267 273 update_post_meta( $post_id, '_auction_status', 'future' ); 268 } elseif ( $start_ date && strtotime( $start_date ) <= strtotime( $current_time ) && $end_date && strtotime( $end_date ) > strtotime( $current_time )) {274 } elseif ( $start_timestamp && $start_timestamp <= $current_timestamp && $end_timestamp && $end_timestamp > $current_timestamp ) { 269 275 update_post_meta( $post_id, '_auction_status', 'live' ); 270 276 } … … 298 304 return $options; 299 305 } 306 307 /** 308 * Normalize datetime input to canonical MySQL format in site timezone. 309 * 310 * @since 1.0.0 311 * @param string $datetime Raw datetime string from form. 312 * @return string Normalized datetime string (Y-m-d H:i:s) or empty string. 313 */ 314 private function normalize_datetime_input( $datetime ) { 315 if ( empty( $datetime ) ) { 316 return ''; 317 } 318 319 $datetime = trim( $datetime ); 320 321 // Split out timezone offset if provided (e.g., +06:00) 322 $parts = preg_split( '/\s+/', $datetime ); 323 $offset = null; 324 325 if ( count( $parts ) >= 2 ) { 326 // Check last token for offset pattern 327 $last = end( $parts ); 328 if ( preg_match( '/^[+-]\d{2}:?\d{2}$/', $last ) ) { 329 $offset = $last; 330 array_pop( $parts ); 331 } 332 } 333 334 $base_string = implode( ' ', $parts ); 335 336 try { 337 if ( $offset ) { 338 $timezone = new DateTimeZone( $offset ); 339 } else { 340 $timezone = function_exists( 'wp_timezone' ) ? wp_timezone() : new DateTimeZone( wp_timezone_string() ); 341 } 342 343 $dt_site = new DateTime( $base_string, $timezone ); 344 if ( ! $offset ) { 345 return $dt_site->format( 'Y-m-d H:i:s' ); 346 } 347 348 $site_timezone = function_exists( 'wp_timezone' ) ? wp_timezone() : new DateTimeZone( wp_timezone_string() ); 349 $dt_site->setTimezone( $site_timezone ); 350 return $dt_site->format( 'Y-m-d H:i:s' ); 351 } catch ( Exception $e ) { 352 // Fallback to strtotime interpretation 353 $timestamp = strtotime( $datetime ); 354 if ( ! $timestamp ) { 355 return ''; 356 } 357 return wp_date( 'Y-m-d H:i:s', $timestamp ); 358 } 359 } 360 361 /** 362 * Convert normalized datetime string to timestamp. 363 * 364 * @since 1.0.0 365 * @param string $datetime Normalized datetime string. 366 * @return int|false Timestamp or false on failure. 367 */ 368 private function datetime_to_timestamp( $datetime ) { 369 if ( empty( $datetime ) ) { 370 return false; 371 } 372 373 try { 374 $timezone = function_exists( 'wp_timezone' ) ? wp_timezone() : new DateTimeZone( wp_timezone_string() ); 375 $dt = new DateTime( $datetime, $timezone ); 376 return $dt->getTimestamp(); 377 } catch ( Exception $e ) { 378 return strtotime( $datetime ); 379 } 380 } 300 381 } -
woo-auction/trunk/includes/class-woo-auction-product.php
r3388741 r3399405 204 204 public function has_auction_started() { 205 205 $start_date = $this->get_auction_start_date(); 206 return $start_date && strtotime( $start_date ) <= current_time( 'timestamp' ); 206 $start_timestamp = $this->get_auction_timestamp( $start_date ); 207 208 return $start_timestamp && $start_timestamp <= current_time( 'timestamp' ); 207 209 } 208 210 … … 215 217 public function is_auction_ended() { 216 218 $end_date = $this->get_auction_end_date(); 217 return $end_date && strtotime( $end_date ) <= current_time( 'timestamp' ); 219 $end_timestamp = $this->get_auction_timestamp( $end_date ); 220 221 return $end_timestamp && $end_timestamp <= current_time( 'timestamp' ); 218 222 } 219 223 … … 291 295 } 292 296 293 $remaining = strtotime( $end_date ) - current_time( 'timestamp' ); 297 $end_timestamp = $this->get_auction_timestamp( $end_date ); 298 if ( ! $end_timestamp ) { 299 return 0; 300 } 301 302 $remaining = $end_timestamp - current_time( 'timestamp' ); 294 303 return max( 0, $remaining ); 295 304 } … … 378 387 379 388 /** 389 * Convert an auction datetime string into a site-local timestamp. 390 * 391 * @since 1.0.0 392 * @param string $datetime MySQL datetime string. 393 * @return int|false Timestamp on success, false otherwise. 394 */ 395 private function get_auction_timestamp( $datetime ) { 396 if ( empty( $datetime ) ) { 397 return false; 398 } 399 400 try { 401 $timezone = function_exists( 'wp_timezone' ) ? wp_timezone() : new DateTimeZone( wp_timezone_string() ); 402 $dt = new DateTime( $datetime, $timezone ); 403 return $dt->getTimestamp(); 404 } catch ( Exception $e ) { 405 return strtotime( $datetime ); 406 } 407 } 408 409 /** 380 410 * Update current bid and bidder 381 411 * -
woo-auction/trunk/readme.txt
r3388757 r3399405 1 === Woo Live Auctionsby CyberCraft ===1 === Live Auctions for WooCommerce by CyberCraft === 2 2 Contributors: mithublue, cybercraftit 3 3 Tags: woocommerce, auction, bidding, live auction, proxy bidding
Note: See TracChangeset
for help on using the changeset viewer.