| 1 |
<?php |
| 2 |
|
| 3 |
namespace StoreEngine\Shortcode; |
| 4 |
|
| 5 |
use StoreEngine\Utils\Helper; |
| 6 |
|
| 7 |
class SingleProductFaq { |
| 8 |
|
| 9 |
public function __construct() { |
| 10 |
add_shortcode( 'storeengine_single_product_faq', [ $this, 'render' ] ); |
| 11 |
} |
| 12 |
|
| 13 |
public function render( $attrs ) { |
| 14 |
$attributes = shortcode_atts( [ |
| 15 |
'product_id' => 0, |
| 16 |
], $attrs ); |
| 17 |
|
| 18 |
$product_id = absint( $attributes['product_id'] ); |
| 19 |
if ( ! $product_id ) { |
| 20 |
$product_id = get_the_ID(); |
| 21 |
} |
| 22 |
if ( ! $product_id ) { |
| 23 |
return ''; |
| 24 |
} |
| 25 |
|
| 26 |
if ( ! (bool) Helper::get_settings( 'enable_faqs', true ) ) { |
| 27 |
return ''; |
| 28 |
} |
| 29 |
|
| 30 |
$groups = storeengine_get_product_faqs( $product_id ); |
| 31 |
if ( empty( $groups ) ) { |
| 32 |
return ''; |
| 33 |
} |
| 34 |
|
| 35 |
ob_start(); |
| 36 |
Helper::get_template( 'single-product/faq.php', [ |
| 37 |
'product_id' => $product_id, |
| 38 |
'groups' => $groups, |
| 39 |
] ); |
| 40 |
|
| 41 |
if ( function_exists( 'storeengine_product_faq_schema' ) ) { |
| 42 |
storeengine_product_faq_schema( $product_id, $groups ); |
| 43 |
} |
| 44 |
|
| 45 |
return ob_get_clean(); |
| 46 |
} |
| 47 |
|
| 48 |
} |
| 49 |
|