| @@ -111,8 +111,67 @@ | ||
| 111 | 111 | |
| 112 | 112 | return $categories; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | + /** | |
| 116 | + * The single "store-wide" FAQ group — the questions every shopper asks on any | |
| 117 | + * product page, regardless of what the product is (payments, shipping, returns, | |
| 118 | + * orders). One group rather than the four themed ones from definition(): it is | |
| 119 | + * flagged "show on all products", so it appears once on every product page, and a | |
| 120 | + * dozen questions in one accordion is a lot. A curated set of six spanning all four | |
| 121 | + * themes reads best. | |
| 122 | + * | |
| 123 | + * @return array { name, slug, icon, description, questions:[ id => title ] } | |
| 124 | + */ | |
| 125 | + public function consolidated_definition() { | |
| 126 | + return [ | |
| 127 | + 'name' => __( 'Shipping, Returns & Payments', 'betterdocs' ), | |
| 128 | + 'slug' => 'store-info', | |
| 129 | + 'icon' => 'truck', | |
| 130 | + 'description' => __( 'Common questions about payments, delivery, returns and orders — shown on every product.', 'betterdocs' ), | |
| 131 | + 'questions' => [ | |
| 132 | + 'payment_methods' => __( 'What payment methods do you accept?', 'betterdocs' ), | |
| 133 | + 'shipping_coverage' => __( 'Where do you ship and how long does delivery take?', 'betterdocs' ), | |
| 134 | + 'shipping_cost' => __( 'How much does shipping cost?', 'betterdocs' ), | |
| 135 | + 'order_tracking' => __( 'How can I track my order?', 'betterdocs' ), | |
| 136 | + 'return_policy' => __( 'What is your return & refund policy?', 'betterdocs' ), | |
| 137 | + 'modify_cancel' => __( 'Can I change or cancel my order after checkout?', 'betterdocs' ), | |
| 138 | + ], | |
| 139 | + ]; | |
| 140 | + } | |
| 141 | + | |
| 142 | + /** | |
| 143 | + * Build the single store-wide group (proxy-shaped) with real, settings-grounded | |
| 144 | + * answers — the deterministic Layer 1 of the WooCommerce product FAQ. Reuses the | |
| 145 | + * same per-question answer builders generate() uses. | |
| 146 | + * | |
| 147 | + * @param array $profile The SiteProfiler profile (uses ['woocommerce'] + ['site']). | |
| 148 | + * @return array { name, slug, description, articles:[{ title, content_html, excerpt }] } | |
| 149 | + */ | |
| 150 | + public function generate_consolidated( array $profile ) { | |
| 151 | + $woo = isset( $profile['woocommerce'] ) && is_array( $profile['woocommerce'] ) ? $profile['woocommerce'] : []; | |
| 152 | + $site = isset( $profile['site'] ) && is_array( $profile['site'] ) ? $profile['site'] : []; | |
| 153 | + $group = $this->consolidated_definition(); | |
| 154 | + | |
| 155 | + $articles = []; | |
| 156 | + foreach ( $group['questions'] as $id => $title ) { | |
| 157 | + $html = $this->answer_html( $id, $woo, $site ); | |
| 158 | + $articles[] = [ | |
| 159 | + 'title' => $title, | |
| 160 | + 'content_html' => $html, | |
| 161 | + 'excerpt' => $this->excerpt( $html ), | |
| 162 | + ]; | |
| 163 | + } | |
| 164 | + | |
| 165 | + return [ | |
| 166 | + 'name' => $group['name'], | |
| 167 | + 'slug' => $group['slug'], | |
| 168 | + 'icon' => $group['icon'], | |
| 169 | + 'description' => $group['description'], | |
| 170 | + 'articles' => $articles, | |
| 171 | + ]; | |
| 172 | + } | |
| 173 | + | |
| 115 | 174 | /* --------------------------------------------------------------------- */ |
| 116 | 175 | /* Answer builders */ |
| 117 | 176 | /* --------------------------------------------------------------------- */ |
| 118 | 177 | |