| 1 |
<?php namespace TierPricingTable\Settings; |
| 2 |
|
| 3 |
use TierPricingTable\Core\ServiceContainerTrait; |
| 4 |
|
| 5 |
/** |
| 6 |
* Class PremiumSettingsManager |
| 7 |
* |
| 8 |
* @package TierPricingTable\Settings |
| 9 |
*/ |
| 10 |
class PremiumSettingsManager { |
| 11 |
|
| 12 |
use ServiceContainerTrait; |
| 13 |
|
| 14 |
public $premiumSubsections = array( |
| 15 |
'tier_pricing_table__subsection_catalog_prices-description', |
| 16 |
'tier_pricing_table__subsection_summary-description', |
| 17 |
'tier_pricing_table__subsection_cart-description', |
| 18 |
'tier_pricing_table__subsection_cart-upsells-description', |
| 19 |
'tier_pricing_table__subsection_non-logged-in-users-description', |
| 20 |
'tier_pricing_table__subsection_rank_math-description', |
| 21 |
'tier_pricing_table__subsection_yoast-seo-description', |
| 22 |
'tier_pricing_table__subsection_seopress-description', |
| 23 |
); |
| 24 |
|
| 25 |
public function __construct() { |
| 26 |
add_action( 'woocommerce_settings_' . Settings::SETTINGS_PAGE, array( $this, 'scripts' ) ); |
| 27 |
} |
| 28 |
|
| 29 |
protected function getConfig(): array { |
| 30 |
return array( |
| 31 |
'premiumSubsections' => $this->premiumSubsections, |
| 32 |
); |
| 33 |
} |
| 34 |
|
| 35 |
public function scripts() { |
| 36 |
?> |
| 37 |
<script> |
| 38 |
jQuery(document).ready(function ($) { |
| 39 |
|
| 40 |
const config = JSON.parse('<?php echo json_encode( $this->getConfig() ); ?>'); |
| 41 |
|
| 42 |
$.each($('[data-tiered-pricing-premium-option]'), function (i, el) { |
| 43 |
const row = $(el).closest('tr'); |
| 44 |
|
| 45 |
if (!row) { |
| 46 |
return; |
| 47 |
} |
| 48 |
const $premiumLabel = jQuery('<span>'); |
| 49 |
$premiumLabel.addClass('tpt_premium_option_label'); |
| 50 |
$premiumLabel.text('Available in premium version'); |
| 51 |
|
| 52 |
row.find('th').append($premiumLabel); |
| 53 |
row.find('td').addClass('tpt_premium_option'); |
| 54 |
|
| 55 |
}); |
| 56 |
|
| 57 |
config.premiumSubsections.forEach(function (subsectionId) { |
| 58 |
|
| 59 |
const $subsection = $('#' + subsectionId); |
| 60 |
const $title = $subsection.prev('h2'); |
| 61 |
|
| 62 |
const $premiumLabel = jQuery('<span>'); |
| 63 |
$premiumLabel.addClass('tpt_premium_subsection_label'); |
| 64 |
$premiumLabel.text('Available in premium version'); |
| 65 |
|
| 66 |
$title.append($premiumLabel); |
| 67 |
|
| 68 |
$subsection.next('table').addClass('tpt_premium_subsection'); |
| 69 |
}); |
| 70 |
|
| 71 |
}); |
| 72 |
</script> |
| 73 |
<?php |
| 74 |
} |
| 75 |
} |