Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('after_wcfm_vendors_manage_membership_details', function($vendor_id) {
- $wcfm_membership_id = get_user_meta( $vendor_id, 'wcfm_membership', true );
- if( $wcfm_membership_id && wcfm_is_valid_membership( $wcfm_membership_id ) ) {
- $subscription = (array) get_post_meta( $wcfm_membership_id, 'subscription', true );
- if( isset( $subscription['is_free'] ) ) {
- ?>
- <script>
- jQuery(function($){
- $('#wcfm_membership_reset_button').click(function(e) {
- e.preventDefault();
- var rconfirm = confirm( wcfm_memberships_cancel_messages.cancel_confirmation );
- if(rconfirm) {
- $('#wcfm_vendor_manage_form_membership_expander').block({
- message: null,
- overlayCSS: {
- background: '#fff',
- opacity: 0.6
- }
- });
- var data = {
- action : 'wcfmvm_membership_reset',
- memberid : $('#wcfm_membership_reset_button').data('memberid'),
- membershipid : $('#wcfm_membership_reset_button').data('membershipid'),
- wcfm_ajax_nonce: wcfm_params.wcfm_ajax_nonce,
- };
- $.post(wcfm_params.ajax_url, data, function(response) {
- if(response) {
- $response_json = $.parseJSON(response);
- console.log($response_json.status);
- if($response_json.status) {
- $('#wcfm_vendor_manage_form_membership_expander .wcfm-message').html('<span class="wcicon-status-completed"></span>' + $response_json.message).addClass('wcfm-success').slideDown( "slow" );
- window.location = window.location.href;
- } else {
- $('.wcfm-message').html('').removeClass('wcfm-success').slideUp();
- $('#wcfm_vendor_manage_form_membership_expander .wcfm-message').html('<span class="wcicon-status-cancelled"></span>' + $response_json.message).addClass('wcfm-error').slideDown();
- }
- $('#wcfm_vendor_manage_form_membership_expander').unblock();
- }
- });
- }
- });
- });
- </script>
- <?php
- echo "<div class='wcfm_clearfix'></div><br />";
- _e( 'Cancel vendor membership: ', 'wc-multivendor-membership' );
- echo '<a href="#" style="float: none; padding: 10px !important;" data-memberid="'.esc_attr($vendor_id).'" data-membershipid="'.esc_attr($wcfm_membership_id).'" id="wcfm_membership_reset_button" class="wcfm_membership_reset_button wcfm_submit_button">' . esc_html__( 'Cancel', 'wc-multivendor-membership' ) . '</a>';
- echo "<div class='wcfm_clearfix'></div><br />";
- }
- }
- });
- add_action('wp_ajax_wcfmvm_membership_reset', function() {
- global $WCFMvm;
- if ( ! check_ajax_referer( 'wcfm_ajax_nonce', 'wcfm_ajax_nonce', false ) ) {
- wp_send_json_error( __( 'Invalid nonce! Refresh your page and try again.', 'wc-frontend-manager' ) );
- wp_die();
- }
- if ( !current_user_can( 'manage_woocommerce' ) && !current_user_can( 'wcfm_vendor' ) && !current_user_can( 'seller' ) && !current_user_can( 'vendor' ) && !current_user_can( 'shop_staff' ) ) {
- wp_send_json_error( esc_html__( 'You don’t have permission to do this.', 'woocommerce' ) );
- wp_die();
- }
- if( isset( $_POST['memberid'] ) && isset($_POST['membershipid']) ) {
- $member_id = absint( $_POST['memberid'] );
- $member_user = new WP_User( $member_id );
- $wcfm_membership_id = absint( $_POST['membershipid'] );
- $WCFMvm->wcfmvm_vendor_membership_cancel( $member_id, $wcfm_membership_id );
- $member_user->remove_role('disable_vendor');
- $member_user->add_role('wcfm_vendor');
- delete_user_meta( $member_id, '_disable_vendor' );
- delete_user_meta( $member_id, 'expired_wcfm_membership' );
- do_action( 'wcfm_vendor_enable_after', $member_id );
- echo '{"status": true, "message": "' . esc_html( __( 'Vendor membership successfully cancelled.', 'wc-multivendor-membership' ) ) . '"}';
- die;
- }
- echo '{"status": false, "message": "' . esc_html( __( 'Vendor membership can not be cancelled right now, please try after sometime.', 'wc-multivendor-membership' ) ) . '"}';
- die;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement