PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 2.3.0
Subscriptions for WooCommerce with Stripe Recurring Payments v2.3.0
2.4.0 2.3.0 2.2.0 2.1.0 2.0.0 1.11.2 1.11.1 1.11.0 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.6 1.9.5 trunk 1.3.0 1.3.1 1.3.2 1.4.0 All 65 releases
← All changes | includes/Api/PlanController.php +38 -0 2.2.0 → 2.3.0 View file →
@@ -195,8 +195,20 @@
195 195 );
196 196
197 197 register_rest_route(
198 198 self::NS,
199 + '/plans/product-user-cancel/(?P<id>\d+)',
200 + array(
201 + array(
202 + 'methods' => WP_REST_Server::EDITABLE,
203 + 'callback' => array( $this, 'save_product_user_cancel' ),
204 + 'permission_callback' => $perm,
205 + ),
206 + )
207 + );
208 +
209 + register_rest_route(
210 + self::NS,
199 211 '/plans/group-products/(?P<id>\d+)',
200 212 array(
201 213 array(
202 214 'methods' => WP_REST_Server::READABLE,
@@ -643,8 +655,34 @@
643 655 'deleted' => true,
644 656 'id' => $id,
645 657 )
646 658 );
659 + }
660 +
661 + /**
662 + * PUT /plans/product-user-cancel/{id} - save whether customers may cancel.
663 + *
664 + * Writes the same `_subscrpt_user_cancel` meta the product editor saves, as
665 + * an explicit "yes" / "no", which checkout copies onto each new subscription.
666 + *
667 + * Body: { enabled: bool }.
668 + *
669 + * @param WP_REST_Request $request Request.
670 + *
671 + * @return \WP_REST_Response|WP_Error
672 + */
673 + public function save_product_user_cancel( WP_REST_Request $request ) {
674 + $product = function_exists( 'wc_get_product' ) ? wc_get_product( (int) $request['id'] ) : null;
675 +
676 + if ( ! $product ) {
677 + return $this->not_found();
678 + }
679 +
680 + $params = $this->read_params( $request );
681 + $product->update_meta_data( '_subscrpt_user_cancel', empty( $params['enabled'] ) ? 'no' : 'yes' );
682 + $product->save();
683 +
684 + return rest_ensure_response( array( 'saved' => true ) );
647 685 }
648 686
649 687 /**
650 688 * POST /plans/bulk-price - set one price on many product/duration relations.