• Resolved maxibel

    (@maxibel)


    The following code makes Dokan work with Brazilian Market on WooCommerce. You can add this to functions.php of your active theme.

    O código abaixo faz com que o Dokan trabalhe com o plugin Brazilian Market on WooCommerce. Você pode adicionar este código ao functions.php do tema ativo. CPF, CNPJ, bairro, número ser?o exibidos tanto no backend wp-admin) quanto no painel do seller.

     //Ajustar campo CNPJ, IE, CPF, bairro e complemento no pedido do Dokan
    
    //Essa primeira parte aqui vai mostrar os dados no painel do fornecedor
    
    add_action( 'dokan_order_details_after_customer_info', function( $order ){
    
    	if( $parent_order_id = $order->get_parent_id() ){
    		$order = wc_get_order( $parent_order_id );
    	}
    
    	$company = $order->get_meta( '_billing_company' );
    	$cpf = $order->get_meta( '_billing_cpf' );
    	$cnpj = $order->get_meta( '_billing_cnpj' );
    	$ie = $order->get_meta( '_billing_ie' );
    	$birthdate = $order->get_meta( '_billing_birthdate' );
    	$sex = $order->get_meta( '_billing_sex' );
    	$cellphone = $order->get_meta( '_billing_cellphone' );
    
    	if( !empty( $company ) ):
    	?>
    	<li><span>Raz?o Social:</span> <?php echo esc_html( $company ); ?></li>
    	<?php
    	endif;
    	if( !empty( $cpf ) ):
    	?>
    	<li><span>CPF:</span> <?php echo esc_html( $cpf ); ?></li>
    	<?php
    	endif;
    	if( !empty( $cnpj ) ):
    	?>
    	<li><span>CNPJ:</span> <?php echo esc_html( $cnpj ); ?></li>
    	<?php
    	endif;
    	if( !empty( $ie ) ):
    	?>
    	<li><span>IE:</span> <?php echo esc_html( $ie ); ?></li>
    	<?php
    	endif;
    	if( !empty( $birthdate ) ):
    	?>
    	<li><span>Aniversário:</span> <?php echo esc_html( $birthdate ); ?></li>
    	<?php
    	endif;
    	if( !empty( $sex ) ):
    	?>
    	<li><span>Sexo:</span> <?php echo esc_html( $sex ); ?></li>
    	<?php
    	endif;
    	if( !empty( $cellphone ) ):
    	?>
    	<li><span>Celular:</span> <?php echo esc_html( $cellphone ); ?></li>
    	<?php
    	endif;
    
    } );
    
    // Essa segunda parte vai ajustar isso no backend do WordPress
    
    function add_brazil_extra_checkout_fields_to_dokan_sub_orders( $order_id, $seller_id ) {
        // Obter o pedido.
        $order = wc_get_order( $order_id );
        // Obter o pedido pai.
        $parent_order = wc_get_order( $order->get_parent_id() );
    
        // Verificar se o pedido pai existe.
        if ( $parent_order ) {
            // Lista de campos adicionais a serem copiados.
            $extra_fields = array(
                '_billing_persontype',
                '_billing_cpf',
                '_billing_rg',
                '_billing_cnpj',
                '_billing_ie',
                '_billing_birthdate',
                '_billing_sex',
                '_billing_number',
                '_billing_neighborhood',
                '_billing_cellphone',
                '_shipping_number',
                '_shipping_neighborhood',
            );
    
            // Loop através dos campos extras.
            foreach ( $extra_fields as $field ) {
                // Obter o valor do campo do pedido pai.
                $field_value = $parent_order->get_meta( $field );
    
                // Definir o valor do campo no pedido.
                $order->update_meta_data( $field, $field_value );
            }
    
            // Salvar as altera??es feitas no pedido.
            $order->save();
        }
    }
    
    // Adicionar a fun??o acima à a??o 'dokan_checkout_update_order_meta'.
    add_action( 'dokan_checkout_update_order_meta', 'add_brazil_extra_checkout_fields_to_dokan_sub_orders', 10, 2 );
Viewing 1 replies (of 1 total)
  • Plugin Support Tanvir Hasan

    (@tanvirh)

    Hi @maxibel

    Thank you for sharing the snippet! We’re glad to hear that it will be helpful for those who are looking to create a marketplace using the Dokan plugin specifically for the Brazilian market. If you have any more snippets or tips that you’d like to share, feel free to share them here.

    However, we are marking this as resolved. Feel free to open a new one for any further issues or queries. We appreciate your contribution!

    Thank you again!

    Best regards,

Viewing 1 replies (of 1 total)
  • The topic ‘Brazilian Fields (CPF, CNPJ) and Dokan’ is closed to new replies.