| 1 |
<?php |
| 2 |
|
| 3 |
namespace StoreEngine\Shortcode; |
| 4 |
|
| 5 |
use StoreEngine\Utils\Helper; |
| 6 |
|
| 7 |
class SingleProductDescription { |
| 8 |
|
| 9 |
public function __construct() { |
| 10 |
add_shortcode( 'storeengine_single_product_description', [ $this, 'render' ] ); |
| 11 |
} |
| 12 |
|
| 13 |
public function render( array $attrs ) { |
| 14 |
$attributes = shortcode_atts( [ |
| 15 |
'product_id' => 0, |
| 16 |
], $attrs ); |
| 17 |
$product_id = absint( $attributes['product_id'] ); |
| 18 |
if ( ! $product_id ) { |
| 19 |
$product_id = get_the_ID(); |
| 20 |
} |
| 21 |
if ( ! $product_id ) { |
| 22 |
return ''; |
| 23 |
} |
| 24 |
|
| 25 |
$product = Helper::get_product( $product_id ); |
| 26 |
if ( ! $product ) { |
| 27 |
return ''; |
| 28 |
} |
| 29 |
|
| 30 |
ob_start(); |
| 31 |
Helper::get_template( 'single-product/description.php', [ |
| 32 |
'content' => $product->get_content() |
| 33 |
] ); |
| 34 |
|
| 35 |
return ob_get_clean(); |
| 36 |
} |
| 37 |
|
| 38 |
} |
| 39 |
|