__( 'Upload', 'bongoto' ), 'url' => bongoto_get_upload_url(), 'icon' => 'upload' )
: array( 'label' => __( 'Start Selling', 'bongoto' ), 'url' => bongoto_get_start_selling_url(), 'icon' => 'upload' )
);
}
}
/* ---------------------------
* 3) Body class
* --------------------------- */
if ( ! function_exists( 'bongoto_dokan_body_class' ) ) {
function bongoto_dokan_body_class( $classes ) {
if ( bongoto_is_dokan_active() ) {
$classes[] = 'has-dokan';
if ( bongoto_is_vendor_user() ) $classes[] = 'is-vendor';
}
return $classes;
}
}
add_filter( 'body_class', 'bongoto_dokan_body_class' );
/* -------------------------------------------------------------
* 5) My Account ড্যাশবোর্ডে "Become a Seller" বাটন (customer)
* ------------------------------------------------------------- */
if ( ! function_exists( 'bongoto_account_become_seller_button' ) ) {
function bongoto_account_become_seller_button() {
if ( ! is_user_logged_in() || bongoto_is_vendor_user() ) return;
$target = '';
if ( bongoto_is_dokan_active() && function_exists( 'dokan_get_page_url' ) ) {
$maybe = dokan_get_page_url( 'registration', 'dokan' );
if ( ! $maybe ) $maybe = dokan_get_page_url( 'reg', 'dokan' );
if ( $maybe ) $target = $maybe;
}
if ( ! $target ) $target = bongoto_get_start_selling_url();
echo '
';
}
}
add_action( 'woocommerce_account_dashboard', 'bongoto_account_become_seller_button', 25 );
/* --------------------------------------------------------------------
* 6) Auto-upgrade handler: ?become_vendor=1 → customer → seller (NO LOOP)
* -------------------------------------------------------------------- */
if ( ! function_exists( 'bongoto_handle_become_vendor' ) ) {
function bongoto_handle_become_vendor() {
if ( empty( $_GET['become_vendor'] ) ) return;
// গেস্ট হলে রিডাইরেক্ট নয়; Woo নিজে লগইন ফর্ম দেখাবে।
if ( ! is_user_logged_in() ) return;
// Already seller → dashboard
if ( bongoto_is_vendor_user() ) {
wp_safe_redirect( bongoto_dokan_dashboard_url() );
exit;
}
$user_id = get_current_user_id();
// Dokan preferred
if ( bongoto_is_dokan_active() ) {
if ( function_exists( 'dokan_set_new_seller_role' ) ) {
dokan_set_new_seller_role( $user_id );
} else {
$user = new WP_User( $user_id );
$user->add_role( 'seller' );
}
update_user_meta( $user_id, 'dokan_enable_selling', 'yes' );
$profile = get_user_meta( $user_id, 'dokan_profile_settings', true );
if ( empty( $profile ) || ! is_array( $profile ) ) {
$display = wp_get_current_user()->display_name;
update_user_meta( $user_id, 'dokan_profile_settings', array(
'store_name' => $display ? ( $display . '\'s Store' ) : 'My Store',
) );
}
wp_safe_redirect( bongoto_dokan_dashboard_url() );
exit;
}
wp_safe_redirect( bongoto_safe_account_url() );
exit;
}
}
add_action( 'template_redirect', 'bongoto_handle_become_vendor', 1 );
/* -------------------------------------------------------------
* 7) Login redirect: রেফারারে become_vendor=1 থাকলে লগইনের পরও সেটি বজায়
* ------------------------------------------------------------- */
if ( ! function_exists( 'bongoto_login_redirect_vendor' ) ) {
function bongoto_login_redirect_vendor( $redirect, $user ) {
$want_vendor = false;
if ( isset( $_REQUEST['become_vendor'] ) && '1' === $_REQUEST['become_vendor'] ) {
$want_vendor = true;
} elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) && false !== strpos( $_SERVER['HTTP_REFERER'], 'become_vendor=1' ) ) {
$want_vendor = true;
}
if ( $want_vendor ) {
return add_query_arg( 'become_vendor', '1', bongoto_safe_account_url() );
}
return $redirect;
}
}
add_filter( 'woocommerce_login_redirect', 'bongoto_login_redirect_vendor', 10, 2 );
/* ---------------------------
* 8) Optional header helpers
* --------------------------- */
if ( ! function_exists( 'bongoto_dokan_account_link' ) ) {
function bongoto_dokan_account_link() {
$url = bongoto_safe_account_url();
echo '';
if ( function_exists( 'bongoto_icon' ) ) {
bongoto_icon( 'account', array( 'width' => 20, 'height' => 20 ) );
}
echo '' . esc_html__( 'My Account', 'bongoto' ) . '';
}
}
if ( ! function_exists( 'bongoto_dokan_store_link' ) ) {
function bongoto_dokan_store_link() {
if ( ! bongoto_is_vendor_user() ) return;
$url = bongoto_dokan_store_url();
echo '' . esc_html__( 'My Store', 'bongoto' ) . '';
}
}