| @@ -1,6 +1,8 @@ | ||
| 1 | 1 | <?php namespace TierPricingTable\Addons\Tools\Settings; |
| 2 | 2 | |
| 3 | +use TierPricingTable\Addons\GlobalTieredPricing\CPT\GlobalTieredPricingCPT; | |
| 4 | +use TierPricingTable\Addons\Tools\PricingTest\PricingTester; | |
| 3 | 5 | use TierPricingTable\Settings\Settings as MainSettings; |
| 4 | 6 | |
| 5 | 7 | class Settings { |
| 6 | 8 | |
| @@ -5,31 +7,40 @@ | ||
| 5 | 7 | class Settings { |
| 6 | 8 | |
| 7 | 9 | public function __construct() { |
| 8 | 10 | |
| 9 | - add_filter( 'tiered_pricing_table/settings/sections', function ( $sections ) { | |
| 11 | + // the utilities panel on the Advanced tab, between the modules and the cache settings | |
| 12 | + add_filter( 'tiered_pricing_table/settings/tools_settings', function ( $settings ) { | |
| 13 | + return array_merge( array( | |
| 14 | + array( | |
| 15 | + // #roles: the "Manage roles" links land here, above the Utilities heading; the app also reads the hash as its tab | |
| 16 | + 'type' => 'tiered-pricing_tools-anchor', | |
| 17 | + ), | |
| 18 | + array( | |
| 19 | + 'title' => __( 'Utilities', 'tier-pricing-table' ), | |
| 20 | + 'desc' => __( 'Manage roles, test what a customer pays, and clean up tiered pricing data.', 'tier-pricing-table' ), | |
| 21 | + 'id' => MainSettings::SETTINGS_PREFIX . 'tools_utilities', | |
| 22 | + 'type' => 'title', | |
| 23 | + ), | |
| 24 | + array( | |
| 25 | + 'type' => 'tiered-pricing_tools-ui', | |
| 26 | + ), | |
| 27 | + array( | |
| 28 | + 'type' => 'sectionend', | |
| 29 | + 'id' => MainSettings::SETTINGS_PREFIX . 'tools_utilities', | |
| 30 | + ), | |
| 31 | + ), $settings ); | |
| 32 | + } ); | |
| 10 | 33 | |
| 11 | - $_sections = array(); | |
| 34 | + add_action( 'woocommerce_admin_field_tiered-pricing_tools-anchor', function () { | |
| 35 | + // printed between two settings tables, so it is not a table row; the scroll margin keeps the heading below the sticky bars | |
| 36 | + ?> | |
| 37 | + <div id="roles" style="scroll-margin-top: 90px;"></div> | |
| 38 | + <?php | |
| 39 | + } ); | |
| 12 | 40 | |
| 13 | - foreach ( $sections as $section ) { | |
| 14 | - | |
| 15 | - if ( $section->getSlug() === 'advanced' ) { | |
| 16 | - $_sections[] = new ToolsSettingsSection(); | |
| 17 | - } | |
| 18 | - | |
| 19 | - $_sections[] = $section; | |
| 20 | - } | |
| 21 | - | |
| 22 | - return $_sections; | |
| 23 | - }, 10 ); | |
| 24 | - | |
| 25 | 41 | add_action( 'woocommerce_admin_field_tiered-pricing_tools-ui', function () { |
| 26 | 42 | ?> |
| 27 | - <style> | |
| 28 | - p.submit { | |
| 29 | - display: none !important; | |
| 30 | - } | |
| 31 | - </style> | |
| 32 | 43 | <tr valign="top"> |
| 33 | 44 | <td colspan="2" class="forminp"> |
| 34 | 45 | <div id="tiered-pricing__feature__tools"></div> |
| 35 | 46 | </td> |
| @@ -45,9 +56,9 @@ | ||
| 45 | 56 | if ( MainSettings::SETTINGS_PAGE !== $settingsTab ) { |
| 46 | 57 | return; |
| 47 | 58 | } |
| 48 | 59 | |
| 49 | - if ( 'tools' !== $section ) { | |
| 60 | + if ( ! in_array( $section, array( 'advanced', 'tools' ), true ) ) { // 'tools' is the pre-7.2.1 link | |
| 50 | 61 | return; |
| 51 | 62 | } |
| 52 | 63 | |
| 53 | 64 | $assetFile = include( plugin_dir_path( __FILE__ ) . '../build/index.asset.php' ); |
| @@ -57,8 +68,28 @@ | ||
| 57 | 68 | $assetFile['version'], true ); |
| 58 | 69 | |
| 59 | 70 | wp_set_script_translations( 'tiered-pricing/feature/tools', 'tier-pricing-table', |
| 60 | 71 | dirname( __FILE__, 5 ) . '/languages' ); |
| 72 | + | |
| 73 | + // a rule to highlight in the Pricing test, from the links on the rules screens | |
| 74 | + $testRule = isset( $_GET[ PricingTester::RULE_PARAM ] ) ? absint( $_GET[ PricingTester::RULE_PARAM ] ) : 0; | |
| 75 | + $testRule = $testRule && GlobalTieredPricingCPT::SLUG === get_post_type( $testRule ) ? $testRule : 0; | |
| 76 | + | |
| 77 | + wp_localize_script( 'tiered-pricing/feature/tools', 'tptToolsConfig', array( | |
| 78 | + 'ajaxUrl' => admin_url( 'admin-ajax.php' ), | |
| 79 | + 'searchProductsNonce' => wp_create_nonce( 'search-products' ), | |
| 80 | + 'searchCustomersNonce' => wp_create_nonce( 'search-customers' ), | |
| 81 | + 'pricingTest' => array( | |
| 82 | + 'rulesEnabled' => PricingTester::rulesEnabled(), | |
| 83 | + 'rulesUrl' => admin_url( 'edit.php?post_type=' . GlobalTieredPricingCPT::SLUG ), | |
| 84 | + 'newRuleUrl' => admin_url( 'post-new.php?post_type=' . GlobalTieredPricingCPT::SLUG ), | |
| 85 | + 'rule' => $testRule ? array( | |
| 86 | + 'id' => $testRule, | |
| 87 | + 'title' => PricingTester::ruleTitle( $testRule ), | |
| 88 | + 'url' => get_edit_post_link( $testRule, 'raw' ), | |
| 89 | + ) : null, | |
| 90 | + ), | |
| 91 | + ) ); | |
| 61 | 92 | |
| 62 | 93 | wp_enqueue_style( 'wp-components' ); |
| 63 | 94 | } ); |
| 64 | 95 | } |