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
← All changes | src/Addons/Tools/API/ToolsEndpoints.php +44 -0 6.5.0 → 8.1.0 View file →
@@ -1,7 +1,9 @@
1 1 <?php namespace TierPricingTable\Addons\Tools\API;
2 2
3 3 use TierPricingTable\Addons\GlobalTieredPricing\CPT\GlobalTieredPricingCPT;
4 +use TierPricingTable\Addons\Tools\PricingTest\PricingTester;
5 +use WP_Error;
4 6 use WP_REST_Request;
5 7
6 8 class ToolsEndpoints {
7 9
@@ -42,8 +44,23 @@
42 44 },
43 45 ),
44 46 ) );
45 47
48 + register_rest_route( self::NAMESPACE, '/pricing_test', array(
49 + array(
50 + 'methods' => 'POST',
51 + 'callback' => array( $this, 'pricingTest' ),
52 + 'permission_callback' => function () {
53 + return current_user_can( 'manage_woocommerce' );
54 + },
55 + 'args' => array(
56 + 'product_id' => array( 'type' => 'integer', 'required' => true ),
57 + 'user_id' => array( 'type' => 'integer', 'default' => 0 ),
58 + 'rule_id' => array( 'type' => 'integer', 'default' => 0 ),
59 + ),
60 + ),
61 + ) );
62 +
46 63 register_rest_route( self::NAMESPACE, '/roles', array(
47 64 array(
48 65 'methods' => 'GET',
49 66 'callback' => array( $this, 'getRoles' ),
@@ -84,8 +101,33 @@
84 101 ),
85 102 ) );
86 103 }
87 104
105 + /**
106 + * The Pricing test: what a customer (0 = visitor) gets for a product, and which global rules apply.
107 + */
108 + public function pricingTest( WP_REST_Request $request ) {
109 + $productId = absint( $request->get_param( 'product_id' ) );
110 + $userId = absint( $request->get_param( 'user_id' ) );
111 + $ruleId = absint( $request->get_param( 'rule_id' ) );
112 +
113 + if ( ! $productId ) {
114 + return new WP_Error( 'tpt_pricing_test_product', __( 'Pick a product first.', 'tier-pricing-table' ), array( 'status' => 400 ) );
115 + }
116 +
117 + if ( $userId && ! get_user_by( 'id', $userId ) ) {
118 + return new WP_Error( 'tpt_pricing_test_customer', __( 'The customer could not be loaded.', 'tier-pricing-table' ), array( 'status' => 400 ) );
119 + }
120 +
121 + $result = ( new PricingTester() )->run( $productId, $userId, $ruleId );
122 +
123 + if ( isset( $result['error'] ) ) {
124 + return new WP_Error( 'tpt_pricing_test', $result['error'], array( 'status' => 400 ) );
125 + }
126 +
127 + return rest_ensure_response( $result );
128 + }
129 +
88 130 public function getRoles() {
89 131 global $wp_roles;
90 132 if ( ! isset( $wp_roles ) ) {
91 133 $wp_roles = new \WP_Roles();
@@ -237,8 +279,10 @@
237 279 if ( $userDeletedCount !== false ) {
238 280 $deletedCount += $userDeletedCount;
239 281 }
240 282 }
283 +
284 + delete_option( \TierPricingTable\Admin\Tips\Tip::SEEN_TIPS_OPTION_KEY );
241 285
242 286 $message = sprintf( 'Successfully cleaned up %d product records.', $deletedCount );
243 287
244 288 return rest_ensure_response( array(