| 1 |
<?php namespace TierPricingTable\Admin\ProductPage; |
| 2 |
|
| 3 |
use TierPricingTable\Core\ServiceContainerTrait; |
| 4 |
use TierPricingTable\TierPricingTablePlugin; |
| 5 |
|
| 6 |
class RoleCustomerPricingTab { |
| 7 |
|
| 8 |
use ServiceContainerTrait; |
| 9 |
|
| 10 |
public function __construct() { |
| 11 |
add_filter( 'woocommerce_product_data_tabs', array( $this, 'register' ), 99, 1 ); |
| 12 |
add_action( 'woocommerce_product_data_panels', array( $this, 'render' ) ); |
| 13 |
} |
| 14 |
|
| 15 |
public function register( $productTabs ): array { |
| 16 |
if ( ! apply_filters( 'tiered_pricing_table/admin/role_customer_pricing_tab_active', false ) ) { |
| 17 |
return $productTabs; |
| 18 |
} |
| 19 |
|
| 20 |
$productTabs['role-customer-pricing-tab'] = array( |
| 21 |
'label' => __( 'Role & Customer Prices', 'tier-pricing-table' ), |
| 22 |
'target' => 'role-customer-pricing-data', |
| 23 |
'class' => ( function () { |
| 24 |
$types = array_merge( TierPricingTablePlugin::getSupportedSimpleProductTypes(), |
| 25 |
TierPricingTablePlugin::getSupportedVariableProductTypes() ); |
| 26 |
|
| 27 |
$classes = array_map( function ( $type ) { |
| 28 |
return 'show_if_' . $type; |
| 29 |
}, $types ); |
| 30 |
|
| 31 |
return $classes; |
| 32 |
} )(), |
| 33 |
); |
| 34 |
|
| 35 |
return $productTabs; |
| 36 |
} |
| 37 |
|
| 38 |
public function render() { |
| 39 |
if ( ! apply_filters( 'tiered_pricing_table/admin/role_customer_pricing_tab_active', false ) ) { |
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
global $post; |
| 44 |
?> |
| 45 |
<div id="role-customer-pricing-data" class="panel woocommerce_options_panel"> |
| 46 |
|
| 47 |
<?php |
| 48 |
if ( ! tpt_fs()->can_use_premium_code() ) { |
| 49 |
$this->renderUpgradeNotice(); |
| 50 |
} |
| 51 |
|
| 52 |
if ( tpt_fs()->can_use_premium_code() && ! tpt_fs()->is_premium() ) { |
| 53 |
$this->getContainer()->getFileManager()->includeTemplate( 'admin/banners/free-version-used-premium-available.php', |
| 54 |
array( 'is_product' => true, ) ); |
| 55 |
} |
| 56 |
|
| 57 |
do_action( 'tiered_pricing_table/admin/role_customer_pricing_tab_begin', $post->ID ); |
| 58 |
?> |
| 59 |
|
| 60 |
<div class="options_group"> |
| 61 |
<?php do_action( 'tiered_pricing_table/admin/role_customer_pricing_tab_content', $post->ID ); ?> |
| 62 |
</div> |
| 63 |
|
| 64 |
<?php do_action( 'tiered_pricing_table/admin/role_customer_pricing_tab_end', $post->ID ); ?> |
| 65 |
</div> |
| 66 |
<?php |
| 67 |
} |
| 68 |
|
| 69 |
protected function renderUpgradeNotice() { |
| 70 |
?> |
| 71 |
<div style="display: flex; align-items: center; border-bottom: 1px solid #eee; justify-content: space-between; background: #f5f5f5; padding: 15px 20px; margin: 0 0 15px;"> |
| 72 |
<div style="display: flex; align-items: center;"> |
| 73 |
<span style="animation: pulse-animation 2s infinite; background: var(--wp-admin-theme-color); color: #fff; padding: 4px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin-right: 15px; display: inline-flex; align-items: center; gap: 4px;"> |
| 74 |
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"> |
| 75 |
<polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"></polygon> |
| 76 |
</svg> |
| 77 |
<?php esc_html_e( 'Premium', 'tier-pricing-table' ); ?> |
| 78 |
</span> |
| 79 |
<span style="color: #3c434a; font-weight: 500;"> |
| 80 |
<?php esc_html_e( 'Unlock Role & Customer pricing rules by upgrading to Premium.', 'tier-pricing-table' ); ?> |
| 81 |
</span> |
| 82 |
</div> |
| 83 |
<div> |
| 84 |
<a target="_blank" class="" href="<?php echo esc_attr( tpt_fs()->get_upgrade_url() ); ?>"> |
| 85 |
<?php esc_html_e( 'Upgrade Now', 'tier-pricing-table' ); ?> |
| 86 |
</a> |
| 87 |
</div> |
| 88 |
</div> |
| 89 |
<?php |
| 90 |
} |
| 91 |
|
| 92 |
} |
| 93 |
|