'product', 'post_status' => 'publish', 'numberposts' => 1, 'fields' => 'ids', 'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- one product per program, tiny table. 'relation' => 'OR', ['key' => BOS_LESSONS_PROGRAM_META, 'value' => (string) $package_id], ['key' => BOS_LESSONS_LEGACY_PROGRAM_META[0], 'value' => (string) $package_id], ['key' => BOS_LESSONS_LEGACY_PROGRAM_META[1], 'value' => (string) $package_id], ], ]); return $ids ? wc_get_product($ids[0]) : null; } // Program page / program grid styles. Called while a shortcode renders; WordPress prints a late enqueue in the footer. function bos_lessons_page_styles() { wp_enqueue_style('bos-lessons-programs', plugin_dir_url(__DIR__) . 'assets/programs.css', [], BOS_LESSONS_VERSION); return ''; } // In the head when the page content itself holds one of the shortcodes, so the page does not flash unstyled. add_action('wp_enqueue_scripts', function () { $post = is_singular() ? get_post() : null; if ($post && (has_shortcode($post->post_content, 'bos_lessons_program') || has_shortcode($post->post_content, 'bos_lessons_programs'))) { bos_lessons_page_styles(); } }); // Price + Buy Now for programs whose page blocks are not filled yet (description or lesson list only). function bos_lessons_buy_box(array $package) { $product = bos_lessons_product_for_package($package['id']); if (!$product) { return ''; } $buy = bos_lessons_buy_url($product); return bos_lessons_page_styles() . '

' . esc_html($package['name']) . '

' . '
' . wp_kses_post($product->get_price_html()) . '
' . '
' . esc_html__('Buy Now', 'bos-lessons') . '' . '' . esc_html__('All programs', 'bos-lessons') . '
'; } function bos_lessons_render_package_page(array $package, array $page) { $product = bos_lessons_product_for_package($package['id']); $title = $page['title'] !== '' ? $page['title'] : $package['name']; $paragraph = function ($text) { return wpautop(esc_html($text)); }; $html = bos_lessons_page_styles(); // alignwide: block themes give it the wide content width (the page is a two-column layout). $html .= '
'; if ($page['eyebrow'] !== '') { $html .= '

' . esc_html($page['eyebrow']) . '

'; } $html .= '

' . esc_html($title) . '

'; if ($page['subtitle'] !== '') { $html .= '

' . esc_html($page['subtitle']) . '

'; } if ($page['intro'] !== '') { $html .= '
' . $paragraph($page['intro']) . '
'; } if ($product) { $html .= '
' . wp_kses_post($product->get_price_html()) . '
'; // Buy Now goes straight to checkout with the program in the cart. $buy = bos_lessons_buy_url($product); $html .= '
' . esc_html__('Buy Now', 'bos-lessons') . ''; } else { $html .= ''; if ($page['note'] !== '') { $html .= '

' . esc_html($page['note']) . '

'; } $html .= '
'; if ($page['image'] !== '') { $html .= '
' . esc_attr($title) . '
'; } $html .= '
'; if (!empty($page['items'])) { $html .= '

' . esc_html($page['inside_title'] !== '' ? $page['inside_title'] : __('What’s inside the program', 'bos-lessons')) . '

'; } return $html . '
'; }