| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Hooks\Handlers; |
| 4 |
|
| 5 |
use FluentCart\App\CPT\FluentProducts; |
| 6 |
use FluentCart\App\Models\ProductDetail; |
| 7 |
|
| 8 |
class TemplateLoader |
| 9 |
{ |
| 10 |
public function init() |
| 11 |
{ |
| 12 |
add_action('fluent_cart/single_product_summary', [$this, 'showTitle'], 10); |
| 13 |
add_action('fluent_cart/single_product_summary', [$this, 'showExcerpt'], 20); |
| 14 |
add_action('fluent_cart/single_product_summary', [$this, 'showBuy'], 25); |
| 15 |
} |
| 16 |
|
| 17 |
public function showTitle() |
| 18 |
{ |
| 19 |
global $post; |
| 20 |
echo wp_kses_post('<h1>' . $post->post_title . '</h1>'); |
| 21 |
} |
| 22 |
|
| 23 |
public function showExcerpt() |
| 24 |
{ |
| 25 |
global $post; |
| 26 |
$short_description = apply_filters('fluent_cart/product_short_description', $post->post_excerpt, []); |
| 27 |
?> |
| 28 |
<div class="fct_product-details_short_description"> |
| 29 |
<?php echo wp_kses_post($short_description); // WPCS: XSS ok. |
| 30 |
?> |
| 31 |
</div> |
| 32 |
<?php |
| 33 |
} |
| 34 |
|
| 35 |
public function showBuy() |
| 36 |
{ |
| 37 |
global $product_detail; |
| 38 |
|
| 39 |
?> |
| 40 |
<p class="<?php echo esc_attr(apply_filters('fluent_cart/price_class', 'price')); ?>"><?php echo wp_kses_post($product_detail->getPriceHtml()); ?></p> |
| 41 |
<button type="submit" name="add-to-cart" value="<?php echo esc_attr($product_detail->id); ?>" |
| 42 |
class="single_add_to_cart_button button alt">Buy Now |
| 43 |
</button> |
| 44 |
<?php |
| 45 |
} |
| 46 |
|
| 47 |
// public function loadTemplate($template) |
| 48 |
// { |
| 49 |
// if (is_singular(FluentProducts::CPT_NAME)) { |
| 50 |
// global $post; |
| 51 |
// unset($GLOBALS['product_detail']); |
| 52 |
// $product = ProductDetail::where('product_id', $post->ID)->first(); |
| 53 |
|
| 54 |
// $GLOBALS['product_detail'] = $product; |
| 55 |
|
| 56 |
// return FLUENTCART_PLUGIN_PATH . 'templates/single-product.php'; |
| 57 |
// } |
| 58 |
|
| 59 |
// return $template; |
| 60 |
// } |
| 61 |
} |
| 62 |
|