cache = Cache::for('menu', WEEK_IN_SECONDS)->connect('post'); if (Site::hasIntegration('square')) { $this->base = '_square_'; } else if (Site::hasIntegration('helcim')) { $this->base = '_helcim_'; } add_action('init', [ $this, 'registerBlock' ]); } public function registerBlock():void { register_block_type($this->path, [ 'render_callback' => [ $this, 'render' ] ]); } protected function buildParams():void { if (is_post_type_archive(BASE.'menu_item')) { $this->params = ['all']; } elseif (is_tax(BASE.'section')) { $this->params = []; } else { $this->params = []; } } public function render(array $attributes, string $content, WP_Block $block) { $this->buildParams(); if (empty($this->params)) { return ''; } jvbInlineStyles('forms'); $key = $this->cache->generateKey($this->params); $this->cache->flush(); return $this->cache->remember( $key, function() { ob_start(); $this->renderBlock(); return ob_get_clean(); } ); } protected function renderBlock():void { $this->renderHeader(); $this->renderMenu(); $this->renderOnThisPage(); } protected function renderHeader():void { $title = 'Our Menu'; if(!in_array('all', $this->params)) { $title = ''.$title.''; } ?>

sections) { $sections = Options::get('menu_section_order'); if (!is_array($sections)) { $sections = []; } $this->sections = $sections; } return $this->sections; } protected function renderMenu():void { $sections = $this->getSections(); foreach ($sections as $section) { $items = new WP_Query([ 'post_type' => BASE.'menu_item', 'order' => 'ASC', 'posts_per_page' => -1, 'tax_query' => [ [ 'taxonomy' => BASE.'section', 'terms' => (int) $section['id'], ] ], 'fields' => 'ids' ]); if ($items->have_posts()) { $slug = sanitize_title($section['name']); ?> getAll(); $values = $meta->getAll([ 'post_title', $this->base.'item_id', $this->base.'price', $this->base.'product_variations', 'max_order', 'min_order', 'step' ]); $priceRange = jvbCurrency($values[$this->base.'price']); $variations = $values[$this->base.'product_variations']; if(!empty($variations) && $variations[0][$this->base.'name'] === '') { $variations = []; } if (!empty($variations)) { $prices = []; foreach ($variations as $row) { if (isset($row[$this->base.'price']) && is_numeric($row[$this->base.'price'])) { $prices[] = (float) $row[$this->base.'price']; } } if (!empty($prices)) { $priceRange = jvbCurrency(min($prices)).' - '.jvbCurrency(max($prices)); } } $max = $values['max_order']??''; $min = $values['min_order']??''; $step = $values['step']??''; $max = ($max === '') ? 50 : $max; $min = ($min === '') ? 0 : $min; $step = ($step === '') ? 1 : $step; ?> details)) { return; } echo jvbOnThisPage(array_keys($this->details)); } }