| 1 |
<?php namespace TierPricingTable\Addons\CustomColumns\Admin; |
| 2 |
|
| 3 |
use TierPricingTable\Settings\Settings as MainSettings; |
| 4 |
|
| 5 |
class CustomColumnsAdmin { |
| 6 |
|
| 7 |
public function __construct() { |
| 8 |
add_action( 'tiered_pricing_table/settings/table_columns/after_fields', function () { |
| 9 |
$columnsManager = \TierPricingTable\Addons\CustomColumns\CustomColumnsManager::getInstance(); |
| 10 |
$hasColumns = ! empty( $columnsManager->getRawColumns() ); |
| 11 |
|
| 12 |
if ( $hasColumns ) { |
| 13 |
return; |
| 14 |
} |
| 15 |
?> |
| 16 |
<div style="height:0; width:100%"></div> |
| 17 |
<div id="tpt-custom-columns-promo-block" style="margin-top: 10px; padding: 10px 15px; background: #f9f9f9; border-left: 4px solid #2271b1; border-radius: 4px; max-width: 700px; display: flex; align-items: center; justify-content: space-between; gap: 15px;"> |
| 18 |
<div> |
| 19 |
<p style="margin: 0 0 4px 0;"><strong><?php esc_html_e( 'Show More Info Next to Prices?', 'tier-pricing-table' ); ?></strong></p> |
| 20 |
<p style="margin: 0; font-size: 13px; color: #646970; line-height: 1.4;"><?php esc_html_e( 'Create additional columns to show exactly how much your customers save, total prices, or per-unit costs alongside each tier.', 'tier-pricing-table' ); ?></p> |
| 21 |
</div> |
| 22 |
<button type="button" id="tpt-toggle-custom-columns" class="button button-primary" style="display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 4px 14px 4px 10px; font-weight: 600; white-space: nowrap; flex-shrink: 0;"> |
| 23 |
<span class="dashicons dashicons-plus" style=" margin-top: 4px; display: flex; align-items: center;"></span> |
| 24 |
<?php esc_html_e( 'Add Custom Columns', 'tier-pricing-table' ); ?> |
| 25 |
</button> |
| 26 |
</div> |
| 27 |
<script> |
| 28 |
document.addEventListener('DOMContentLoaded', function() { |
| 29 |
var toggleBtn = document.getElementById('tpt-toggle-custom-columns'); |
| 30 |
var customColumnsDiv = document.getElementById('tiered-pricing__feature__custom-columns'); |
| 31 |
var promoBlock = document.getElementById('tpt-custom-columns-promo-block'); |
| 32 |
if (toggleBtn && customColumnsDiv) { |
| 33 |
customColumnsDiv.style.display = 'none'; |
| 34 |
toggleBtn.addEventListener('click', function(e) { |
| 35 |
e.preventDefault(); |
| 36 |
if (promoBlock) { |
| 37 |
promoBlock.style.display = 'none'; |
| 38 |
} |
| 39 |
customColumnsDiv.style.display = 'block'; |
| 40 |
}); |
| 41 |
} |
| 42 |
}); |
| 43 |
</script> |
| 44 |
<?php |
| 45 |
} ); |
| 46 |
|
| 47 |
add_action( 'tiered_pricing_table/settings/table_columns/end', function () { |
| 48 |
?> |
| 49 |
<div id="tiered-pricing__feature__custom-columns"></div> |
| 50 |
<?php |
| 51 |
} ); |
| 52 |
|
| 53 |
add_action( 'admin_enqueue_scripts', function () { |
| 54 |
|
| 55 |
$settingsTab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : ''; |
| 56 |
|
| 57 |
if ( MainSettings::SETTINGS_PAGE !== $settingsTab ) { |
| 58 |
return; |
| 59 |
} |
| 60 |
|
| 61 |
$buildDir = dirname( __FILE__, 2 ) . '/build'; |
| 62 |
|
| 63 |
if ( ! file_exists( $buildDir . '/index.asset.php' ) ) { |
| 64 |
return; |
| 65 |
} |
| 66 |
|
| 67 |
$assetFile = include( $buildDir . '/index.asset.php' ); |
| 68 |
|
| 69 |
wp_enqueue_script( 'tiered-pricing/feature/custom-columns', |
| 70 |
plugins_url( 'build/index.js', dirname( __FILE__ ) ), $assetFile['dependencies'], |
| 71 |
$assetFile['version'], true ); |
| 72 |
|
| 73 |
wp_localize_script( 'tiered-pricing/feature/custom-columns', 'tptCustomColumns', array( |
| 74 |
'isPremium' => function_exists( 'tpt_fs' ) && tpt_fs()->can_use_premium_code(), |
| 75 |
'upgradeUrl' => function_exists( 'tpt_fs' ) ? tpt_fs()->get_upgrade_url() : '#', |
| 76 |
) ); |
| 77 |
|
| 78 |
wp_set_script_translations( 'tiered-pricing/feature/custom-columns', 'tier-pricing-table', |
| 79 |
dirname( __FILE__, 5 ) . '/languages' ); |
| 80 |
} ); |
| 81 |
} |
| 82 |
} |
| 83 |
|