$label ) { $new[ $key ] = $label; // Insert after Dashboard or Orders for better visibility. if ( ! $inserted && ( 'dashboard' === $key || 'orders' === $key ) ) { $new['bongoto-become-vendor'] = __( 'Start Selling', 'bongoto' ); $inserted = true; } } if ( ! $inserted ) { $new['bongoto-become-vendor'] = __( 'Start Selling', 'bongoto' ); } return $new; }, 50 ); /** * D) Core handler (what to do when user hits the endpoint) */ function bongoto_handle_become_vendor() { $my_account = function_exists( 'wc_get_page_permalink' ) ? trailingslashit( wc_get_page_permalink( 'myaccount' ) ) : home_url( '/my-account/' ); // Must be logged in to proceed. if ( ! is_user_logged_in() ) { wp_safe_redirect( $my_account ); exit; } $user_id = get_current_user_id(); // Require Dokan for vendor flow. if ( ! bongoto_dc_is_dokan_active() ) { wp_safe_redirect( $my_account ); exit; } $dashboard_url = function_exists( 'dokan_get_page_url' ) ? dokan_get_page_url( 'dashboard', 'dokan' ) : $my_account; // Already a seller? Go to Dokan Dashboard. if ( function_exists( 'dokan_is_user_seller' ) && dokan_is_user_seller( $user_id ) ) { wp_safe_redirect( $dashboard_url ); exit; } // Auto-approve path: if the constant is defined & truthy. if ( defined( 'BONGOTO_AUTO_APPROVE_VENDOR' ) && BONGOTO_AUTO_APPROVE_VENDOR ) { $user = get_userdata( $user_id ); if ( $user instanceof WP_User ) { $user->set_role( 'seller' ); // Dokan's default vendor role is usually 'seller'. } else { $u = new WP_User( $user_id ); $u->set_role( 'seller' ); } update_user_meta( $user_id, 'dokan_enable_selling', 'yes' ); wp_safe_redirect( $dashboard_url ); exit; } // Manual-approval path: show an informational notice. if ( function_exists( 'wc_print_notice' ) ) { wc_print_notice( __( 'Your request to become a vendor has been received. Please wait for approval.', 'bongoto' ), 'notice' ); } echo '

' . esc_html__( 'Back to My Account', 'bongoto' ) . '

'; } /** * WooCommerce endpoint hook (only if Woo is active) */ if ( bongoto_dc_is_woo_active() ) { add_action( 'woocommerce_account_bongoto-become-vendor_endpoint', 'bongoto_handle_become_vendor' ); } /** * E) Safety net: query-var fallback (avoids 404 if pretty permalinks fail) * - Normal: /my-account/bongoto-become-vendor/ * - Fallback qs: ?bongoto-become-vendor=1 */ add_action( 'template_redirect', function () { if ( ! bongoto_dc_is_woo_active() ) { return; } $triggered = ( get_query_var( 'bongoto-become-vendor', false ) !== false ) || isset( $_GET['bongoto-become-vendor'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( $triggered ) { bongoto_handle_become_vendor(); exit; } } );