| 1 |
<?php |
| 2 |
|
| 3 |
namespace StoreEngine\Shortcode; |
| 4 |
|
| 5 |
use StoreEngine\Utils\Template; |
| 6 |
|
| 7 |
class SingleProductGallery { |
| 8 |
|
| 9 |
public function __construct() { |
| 10 |
add_shortcode( 'storeengine_single_product_gallery', [ $this, 'render' ] ); |
| 11 |
} |
| 12 |
|
| 13 |
public function render( array $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 |
// Custom vanilla-JS gallery — loaded only when the product has media. |
| 27 |
storeengine_enqueue_product_gallery_assets( $product_id ); |
| 28 |
|
| 29 |
ob_start(); |
| 30 |
Template::get_template( 'single-product/gallery.php', [ |
| 31 |
'product_id' => $product_id, |
| 32 |
] ); |
| 33 |
|
| 34 |
return ob_get_clean(); |
| 35 |
} |
| 36 |
|
| 37 |
} |
| 38 |
|