__( 'Not saved: you do not manage the shop.', 'ai-eshop-optimizer' ) ) ); } $cutoff = isset( $_POST['cutoff'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['cutoff'] ) ) : ''; $days = isset( $_POST['days'] ) && is_array( $_POST['days'] ) ? array_map( 'absint', wp_unslash( $_POST['days'] ) ) : array(); if ( '' !== $cutoff && '' === AIEO_Dispatch_Cutoff::time( $cutoff ) ) { wp_send_json_error( array( 'message' => __( 'Not saved: give the cut-off as a time of day, such as 15:00, or leave it empty.', 'ai-eshop-optimizer' ) ) ); } if ( '' !== $cutoff && array() === AIEO_Dispatch_Cutoff::days( $days ) ) { wp_send_json_error( array( 'message' => __( 'Not saved: tick at least one dispatch day, or leave the cut-off empty.', 'ai-eshop-optimizer' ) ) ); } $save = array( 'cutoff' => $cutoff, 'days' => $days, ); foreach ( array_keys( AIEO_Dispatch_Cutoff::STRING_NAMES ) as $key ) { $save[ $key ] = isset( $_POST[ $key ] ) ? sanitize_text_field( wp_unslash( (string) $_POST[ $key ] ) ) : ''; } $saved = AIEO_Dispatch_Cutoff::update( $save ); foreach ( AIEO_Dispatch_Cutoff::STRING_NAMES as $key => $name ) { if ( '' !== $saved[ $key ] ) { do_action( 'wpml_register_single_string', AIEO_Dispatch_Cutoff::STRINGS_DOMAIN, $name, $saved[ $key ] ); if ( function_exists( 'pll_register_string' ) ) { pll_register_string( $name, $saved[ $key ], AIEO_Dispatch_Cutoff::STRINGS_DOMAIN ); } } } do_action( 'aieo_purge_page_cache' ); wp_send_json_success( array( 'message' => __( 'Saved.', 'ai-eshop-optimizer' ) ) ); } private static function day_choices() { global $wp_locale; $days = array(); for ( $day = 1; $day <= 7; $day++ ) { $days[ $day ] = $wp_locale instanceof WP_Locale ? (string) $wp_locale->get_weekday( $day % 7 ) : gmdate( 'l', ( 3 + $day % 7 ) * DAY_IN_SECONDS ); } return $days; } private static function now_line() { $moment = AIEO_Dispatch_Cutoff::moment(); $line = _x( 'In stock', 'the stock line, before when an order is shipped', 'ai-eshop-optimizer' ) . AIEO_Dispatch_Cutoff::SEPARATOR . AIEO_Dispatch_Cutoff::words( $moment[0], $moment[1] ); $when = wp_date( 'l ' . (string) get_option( 'time_format', 'H:i' ) ); return esc_html( sprintf( __( 'Now, %1$s in the shop\'s time (%2$s), a product in stock reads: “%3$s”.', 'ai-eshop-optimizer' ), $when, wp_timezone_string(), $line ) ); } public function render_subtab() { $s = AIEO_Dispatch_Cutoff::settings(); $form = 'aieo-card-dispatch-cutoff-form'; list( $open, $close ) = AIEO_DMM_UI::card( array( 'anchor' => 'dispatch-cutoff-settings', 'icon' => 'clock', 'title' => __( 'When an order is shipped', 'ai-eshop-optimizer' ), 'description' => __( 'The stock line of a product in stock says when an order placed now is shipped: before the cut-off on a dispatch day “In stock · ordered before 15:00, shipped today”, after it “shipped tomorrow”, and before a day without dispatch the next dispatch day, “shipped on Monday”. In the shop\'s time zone. Products on back-order, out of stock, virtual or not for sale keep their line as it is.', 'ai-eshop-optimizer' ), 'footer' => \Rooster\Admin\States::save_button( $form ), ) ); echo $open; $rows = \Rooster\Admin\Ui::field_row( array( 'id' => 'aieo-dc-cutoff', 'label' => __( 'Cut-off time', 'ai-eshop-optimizer' ), 'control' => \Rooster\Admin\Ui::input( 'cutoff', $s['cutoff'], array( 'id' => 'aieo-dc-cutoff', 'type' => 'time', 'short' => true ) ), 'help' => __( 'Orders placed before this time on a dispatch day are shipped the same day. Empty: off, and the stock line stays as WooCommerce prints it.', 'ai-eshop-optimizer' ), ) ); $rows .= \Rooster\Admin\Ui::field_row( array( 'id' => 'aieo-dc-days', 'group' => true, 'label' => __( 'Dispatch days', 'ai-eshop-optimizer' ), 'control' => \Rooster\Admin\Ui::checks( 'days', self::day_choices(), array_map( 'strval', $s['days'] ), array( 'inline' => true ) ), 'help' => __( 'The days orders leave the shop. Monday to Friday unless you choose otherwise.', 'ai-eshop-optimizer' ), ) ); $words = array( 'today' => array( __( 'Words before the cut-off', 'ai-eshop-optimizer' ), __( 'ordered before {time}, shipped today', 'ai-eshop-optimizer' ), __( '{time} is the cut-off in the site\'s time format.', 'ai-eshop-optimizer' ) ), 'tomorrow' => array( __( 'Words after the cut-off', 'ai-eshop-optimizer' ), __( 'shipped tomorrow', 'ai-eshop-optimizer' ), __( 'When the next day is a dispatch day.', 'ai-eshop-optimizer' ) ), 'later' => array( __( 'Words for a later day', 'ai-eshop-optimizer' ), __( 'shipped on {day}', 'ai-eshop-optimizer' ), __( 'After the last cut-off before days without dispatch (a Friday afternoon, a Saturday); {day} is the next dispatch day.', 'ai-eshop-optimizer' ) ), ); foreach ( $words as $key => $word ) { $rows .= \Rooster\Admin\Ui::field_row( array( 'id' => 'aieo-dc-' . $key, 'label' => $word[0], 'control' => \Rooster\Admin\Ui::input( $key, $s[ $key ], array( 'id' => 'aieo-dc-' . $key, 'medium' => true, 'placeholder' => $word[1] ) ), 'help' => $word[2] . ' ' . __( 'Empty: the built-in words, in each visitor\'s language. With WPML or Polylang, translate yours under String Translation (Rooster One).', 'ai-eshop-optimizer' ), ) ); } echo AIEO_DMM_UI::card_form( 'aieo_dmm_dispatch_cutoff_save', 'dispatch_cutoff', $form, '
' . $rows . '
' ); if ( AIEO_Dispatch_Cutoff::on() ) { echo \Rooster\Admin\Ui::notice( self::now_line(), 'info', array( 'inline' => true ) ); } if ( '' === (string) get_option( 'timezone_string' ) ) { echo \Rooster\Admin\Ui::notice( esc_html__( 'The site\'s time zone is a fixed offset from UTC, which does not follow summer time: where the clocks change, the cut-off is an hour out half the year. Choose the shop\'s city instead.', 'ai-eshop-optimizer' ) . ' ' . esc_html__( 'The site\'s time zone', 'ai-eshop-optimizer' ) . '', 'warning', array( 'inline' => true ) ); } echo $close; } }