'0' ), $atts ); return function_exists( 'wc_price' ) ? wp_kses_post( wc_price( (float) $atts['amount'] ) ) : esc_html( $atts['amount'] ); } ); /** * The menu page: WooCommerce's shop page. * * @return string */ function sofrah_board_menu_url() { return function_exists( 'wc_get_page_permalink' ) && wc_get_page_id( 'shop' ) > 0 ? wc_get_page_permalink( 'shop' ) : home_url( '/#menu' ); } /** * [sofrah_back_to_menu label="" button="0"]: a link back to the menu. */ add_shortcode( 'sofrah_back_to_menu', function ( $atts ) { $atts = shortcode_atts( array( 'label' => '', 'button' => '0' ), $atts ); $label = $atts['label'] ? $atts['label'] : ( '1' === $atts['button'] ? __( 'See the menu', 'sofrah-order-board' ) : __( '← Back to the menu', 'sofrah-order-board' ) ); if ( '1' === $atts['button'] ) { return '
'; } return ''; } ); /** * [sofrah_ready_minutes]: the usual pickup time, in minutes. */ add_shortcode( 'sofrah_ready_minutes', function () { $minutes = (int) sofrah_board_setting( 'lead_minutes' ); return esc_html( (string) max( 1, $minutes ) ); } ); /** * Links from one menu section's page to the full menu and the other sections. * * @param array $args The term query for the menu's sections. * @param int $current The section being shown. * @return string */ function sofrah_board_section_links( $args, $current ) { $terms = get_terms( $args ); if ( is_wp_error( $terms ) || ! $terms ) { $terms = array(); } $out = ''; } /** * [sofrah_menu category=""]: the menu as a restaurant menu, grouped by section, with photographs when dishes have them, dietary and allergen notes, prices and an Add button. * On a menu-section page only that section is shown. Dishes with choices go to their own page. While ordering is closed the buttons are off. */ add_shortcode( 'sofrah_menu', function ( $atts ) { if ( ! function_exists( 'wc_get_products' ) ) { return ''; } $atts = shortcode_atts( array( 'category' => '' ), $atts ); $args = array( 'taxonomy' => 'product_cat', 'hide_empty' => true, 'orderby' => 'menu_order', // WooCommerce's own category order. 'exclude' => array( (int) get_option( 'default_product_cat' ) ), // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- one term: the default 'Uncategorized' section. ); if ( $atts['category'] ) { $args['slug'] = array_map( 'trim', explode( ',', $atts['category'] ) ); } elseif ( function_exists( 'is_product_category' ) && is_product_category() ) { // One section's page: the links lead to the other sections, whatever this one holds. $section_nav = sofrah_board_section_links( $args, get_queried_object_id() ); $args['include'] = array( get_queried_object_id() ); } $section_nav = $section_nav ?? ''; $terms = get_terms( $args ); if ( is_wp_error( $terms ) || ! $terms ) { return $section_nav . '' . esc_html__( 'The menu is being prepared. Please check back soon.', 'sofrah-order-board' ) . '
'; } $open = sofrah_board_ordering_open(); $sections = array(); foreach ( $terms as $t ) { $products = wc_get_products( array( 'status' => 'publish', 'visibility' => 'catalog', 'limit' => 100, 'category' => array( $t->slug ), 'orderby' => 'menu_order', 'order' => 'ASC', ) ); if ( $products ) { $sections[] = array( $t, $products ); } } if ( ! $sections ) { return $section_nav . '' . esc_html__( 'The menu is being prepared. Please check back soon.', 'sofrah-order-board' ) . '
'; } wp_enqueue_script( 'wc-add-to-cart' ); $out = $section_nav; if ( count( $sections ) > 1 ) { $out .= ''; } foreach ( $sections as $sec ) { list( $t, $products ) = $sec; $out .= ''; } return $out; } );