PluginProbe
Tiered Pricing Table for WooCommerce / 8.1.0
Tiered Pricing Table for WooCommerce v8.1.0
8.1.0 8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 All 92 releases
tier-pricing-table / src / Addons / Tools / Settings / Settings.php

Settings.php in Tiered Pricing Table for WooCommerce 8.1.0, at src/Addons/Tools/Settings/Settings.php

97 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\Tools\Settings;
2
3 use TierPricingTable\Addons\GlobalTieredPricing\CPT\GlobalTieredPricingCPT;
4 use TierPricingTable\Addons\Tools\PricingTest\PricingTester;
5 use TierPricingTable\Settings\Settings as MainSettings;
6
7 class Settings {
8
9 public function __construct() {
10
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 } );
33
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 } );
40
41 add_action( 'woocommerce_admin_field_tiered-pricing_tools-ui', function () {
42 ?>
43 <tr valign="top">
44 <td colspan="2" class="forminp">
45 <div id="tiered-pricing__feature__tools"></div>
46 </td>
47 </tr>
48 <?php
49 } );
50
51 add_action( 'admin_enqueue_scripts', function () {
52
53 $settingsTab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : '';
54 $section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : '';
55
56 if ( MainSettings::SETTINGS_PAGE !== $settingsTab ) {
57 return;
58 }
59
60 if ( ! in_array( $section, array( 'advanced', 'tools' ), true ) ) { // 'tools' is the pre-7.2.1 link
61 return;
62 }
63
64 $assetFile = include( plugin_dir_path( __FILE__ ) . '../build/index.asset.php' );
65
66 wp_enqueue_script( 'tiered-pricing/feature/tools',
67 plugins_url( 'build/index.js', dirname( __FILE__ . '../' ) ), $assetFile['dependencies'],
68 $assetFile['version'], true );
69
70 wp_set_script_translations( 'tiered-pricing/feature/tools', 'tier-pricing-table',
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 ) );
92
93 wp_enqueue_style( 'wp-components' );
94 } );
95 }
96 }
97