| 1 |
<?php namespace TierPricingTable\Blocks; |
| 2 |
|
| 3 |
use TierPricingTable\PricingTable; |
| 4 |
use WP_Post; |
| 5 |
|
| 6 |
class GutenbergBlocks { |
| 7 |
|
| 8 |
public function __construct() { |
| 9 |
|
| 10 |
register_block_type( __DIR__ . '/build', array( |
| 11 |
'render_callback' => function ( $attributes, $content ) { |
| 12 |
|
| 13 |
$attributes = wp_parse_args( $attributes, array( |
| 14 |
'displayType' => 'table', |
| 15 |
'activeTierColor' => '#3858e9', |
| 16 |
'title' => '', |
| 17 |
'showDiscountColumn' => true, |
| 18 |
'quantityColumnTitle' => '', |
| 19 |
'discountColumnTitle' => '', |
| 20 |
'priceColumnTitle' => '', |
| 21 |
) ); |
| 22 |
|
| 23 |
global $post; |
| 24 |
|
| 25 |
if ( ! ( $post instanceof WP_Post ) ) { |
| 26 |
return ''; |
| 27 |
} |
| 28 |
|
| 29 |
ob_start(); |
| 30 |
PricingTable::getInstance()->renderPricingTable( $post->ID, null, array( |
| 31 |
'display_type' => $attributes['displayType'], |
| 32 |
'active_tier_color' => $attributes['activeTierColor'], |
| 33 |
'title' => $attributes['title'], |
| 34 |
'show_discount_column' => $attributes['showDiscountColumn'], |
| 35 |
'discount_column_title' => $attributes['discountColumnTitle'], |
| 36 |
'price_column_title' => $attributes['priceColumnTitle'], |
| 37 |
'quantity_column_title' => $attributes['quantityColumnTitle'], |
| 38 |
) ); |
| 39 |
|
| 40 |
return ob_get_clean(); |
| 41 |
}, |
| 42 |
) ); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|