'closed', 'text' => $message, ); } if ( $decision->is_scheduled() && null !== $decision->get_scheduled_for() ) { return array( 'type' => 'info', 'text' => sprintf( /* translators: %s: when the store can fulfil the order, e.g. "tomorrow 9:00 am". */ __( 'Orders placed now are scheduled for %s.', 'hourgate' ), OrderingPolicy::format_when( (int) $decision->get_scheduled_for() ) ), ); } return null; } /** * Whether this page could place an order: a cart with items, and not * order-pay or order-received (paying is never told "we're closed", D1). * * @return bool */ private static function has_order_to_place() { if ( ! function_exists( 'WC' ) || ! function_exists( 'is_wc_endpoint_url' ) ) { return false; } if ( is_wc_endpoint_url( 'order-pay' ) || is_wc_endpoint_url( 'order-received' ) ) { return false; } $cart = WC()->cart; return $cart instanceof \WC_Cart && ! $cart->is_empty(); } /** * Classic cart and checkout: print the notice above the page. * * @return void */ public static function print_classic() { $notice = self::notice(); if ( null === $notice || ! function_exists( 'wc_print_notice' ) ) { return; } // WooCommerce's "notice" type is the info notice; the closed message is one too (OW-048). wc_print_notice( Message::html( $notice['text'] ), 'notice' ); } /** * Cart and Checkout blocks: put the banner above the block. The closed * message is a warning, not an error: the blocks would put WooCommerce's * "Please fix the following error" heading above an error (OW-048). The * cart preloaded into these pages leaves the error out * (`Checkout::hide_from_preloaded_cart()`), and the status script removes * it from the blocks' notices when a later cart response brings it back. * The script also relabels Place order with `data-place-order-label`. * * The closed banner is printed whenever the cart has an order to place, * hidden and empty while checkout is allowed, so a page loaded while open * still has it and the script: it is shown when the status says checkout * is refused, or when the server refuses Place order first (OW-048). * * @param mixed $content Rendered block HTML. * @return mixed */ public static function prepend_to_block( $content ) { if ( ! is_string( $content ) || ! self::has_order_to_place() ) { return $content; } $notice = self::notice(); $closed = null !== $notice && 'closed' === $notice['type']; $html = ''; if ( null !== $notice && 'info' === $notice['type'] ) { $html .= sprintf( '
', esc_html( $notice['text'] ) ); } // The status script shows and hides the closed notice, and holds Place order while it is shown. Assets::need(); $html .= sprintf( '', $closed ? '1' : '0', /* translators: Label of the Checkout block's Place order button while the store is closed. */ esc_attr__( 'Ordering is closed', 'hourgate' ), // Not `hidden`: WooCommerce's banner CSS sets `display` and would win. $closed ? '' : ' style="display:none"', $closed ? esc_html( $notice['text'] ) : '' ); return $html . $content; } /** * Block themes: a rejected `?add-to-cart=` queues its notice, but pages * without a notices area never print it. Print what is queued at the top * of the body, once (printing clears it, so pages that do have a notices * area don't repeat it). * * @return void */ public static function print_rejected_add() { if ( ! AddToCart::was_rejected() || ! function_exists( 'wc_print_notices' ) || ! function_exists( 'wp_is_block_theme' ) || ! wp_is_block_theme() ) { return; } echo '