| 1 |
<?php namespace TierPricingTable\Frontend; |
| 2 |
|
| 3 |
use TierPricingTable\Core\ServiceContainerTrait; |
| 4 |
use TierPricingTable\PricingTable; |
| 5 |
|
| 6 |
class PricingTableShortcode { |
| 7 |
|
| 8 |
use ServiceContainerTrait; |
| 9 |
|
| 10 |
const TAG = 'tiered-pricing-table'; |
| 11 |
|
| 12 |
public function __construct() { |
| 13 |
add_shortcode( self::TAG, array( $this, 'render' ) ); |
| 14 |
} |
| 15 |
|
| 16 |
public function render( $args ) { |
| 17 |
|
| 18 |
$args = wp_parse_args( $args, array( |
| 19 |
'product_id' => null, |
| 20 |
'display' => true, |
| 21 |
) ); |
| 22 |
|
| 23 |
if ( $args['product_id'] ) { |
| 24 |
$productID = intval( $args['product_id'] ); |
| 25 |
} else { |
| 26 |
global $post; |
| 27 |
|
| 28 |
if ( ! $post ) { |
| 29 |
return ''; |
| 30 |
} |
| 31 |
|
| 32 |
$productID = $post->ID; |
| 33 |
} |
| 34 |
|
| 35 |
$product = wc_get_product( $productID ); |
| 36 |
|
| 37 |
ob_start(); |
| 38 |
|
| 39 |
if ( $product ) { |
| 40 |
PricingTable::getInstance()->renderPricingTable( $product->get_id(), null, $args ); |
| 41 |
} |
| 42 |
|
| 43 |
return ob_get_clean(); |
| 44 |
} |
| 45 |
} |
| 46 |
|