How display custom section in my account page?
-
Hi, how do I show a new custom section on “my account” page? So that the user can modify the new fields added?
-
Hello @nagato76
Please add a new field in the Billing or Shipping section. This field will then appear in the My Account > Addresses tab.
It is not possible to add custom sections here. There are default and custom fields from the Billing and Shipping sectionHi , I added 3 new fields in billing and 1 in shipping , the fields is working on all pages , but I cant find the correct ‘My Account’ command to show in the Addresses tab. can you please help me telling the command that I need to use to load the field in the myAccount address section?
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' ); // Our hooked in function – $fields is passed via the filter! function custom_override_checkout_fields( $fields ) { $fields['billing']['billing_address_number'] = array( 'label' => __('n.', 'woocommerce') , 'placeholder' => _x('numero', 'placeholder', 'woocommerce') , 'required' => true , 'class' => array('form-row-wide') , 'clear' => true , 'type' => 'text' ); $fields['billing']['billing_cpf_cnpj'] = array( 'label' => __('Cpf / Cnpj', 'woocommerce') , 'placeholder' => _x('', 'placeholder', 'woocommerce') , 'required' => true , 'class' => array('form-row-wide') , 'clear' => true , 'type' => 'text' ); $fields['billing']['billing_mobile'] = array( 'label' => __('Celular', 'woocommerce') , 'placeholder' => _x('Celular', 'placeholder', 'woocommerce') , 'required' => false , 'class' => array('form-row-wide') , 'clear' => true , 'type' => 'text' ); $fields['shipping']['shipping_address_number'] = array( 'label' => __('n.', 'woocommerce') , 'placeholder' => _x('numero', 'placeholder', 'woocommerce') , 'required' => true , 'class' => array('form-row-wide') , 'clear' => true , 'type' => 'text' ); return $fields; }
function save_custom_checkout_fields( $order_id, $posted ){ if( isset( $data['billing_cpf_cnpj'] ) ) { $order->update_meta_data('_billing_cpf_cnpj', $data['billing_cpf_cnpj'] ); } if( isset( $data['billing_mobile'] ) ) { $order->update_meta_data('_billing_mobile', $data['billing_mobile'] ); } if( isset( $data['billing_address_number'] ) ) { $order->update_meta_data('_billing_address_number', $data['billing_address_number'] ); } if( isset( $data['shipping_address_number'] ) ) { $order->update_meta_data('_shipping_address_number', $data['shipping_address_number'] ); } } add_action( 'woocommerce_checkout_update_order_meta', 'save_custom_checkout_fields', 10, 2 );
// display the extra data on order received page and my-account order review function display_custom_order_data( $order_id ){ $order = wc_get_order( $order_id ); echo "<p>Cpf/Cnpj:" . $order->get_meta( '_billing_cpf_cnpj' ) . "</p>"; echo "<p>Celular:" . $order->get_meta( '_billing_mobile' ) . "</p>"; echo "<p>Numero:" . $order->get_meta( '_billing_address_number' ) . "</p>"; echo "<p>Numero Shipping:" . $order->get_meta( '_shipping_address_number' ) . "</p>"; } add_action( 'woocommerce_thankyou', 'display_custom_order_data', 10 ); add_action( 'woocommerce_view_order', 'display_custom_order_data', 10 ); //display extradata on admin woocommerce function billing_to_order($order){ echo "<p><strong>Cpf/Cnpj:</strong> " . $order->get_meta( '_billing_cpf_cnpj' ) . "</p>"; echo "<p><strong>Celular:</strong> " . $order->get_meta( '_billing_mobile' ) . "</p>"; echo "<p><strong>Número:</strong> " . $order->get_meta( '_billing_address_number' ) . "</p>"; echo "<p>Numero Shipping:" . $order->get_meta( '_shipping_address_number' ) . "</p>"; } add_action( 'woocommerce_admin_order_data_after_billing_address', 'billing_to_order', 10, 1 );
-
This reply was modified 3 years ago by
luizhcrivelli.
Hello @luizhcrivelli
If the fields were added using our plugin then there is no need to insert additional snippets to show them on the Address page.
Display On settings -
This reply was modified 3 years ago by
- The topic ‘How display custom section in my account page?’ is closed to new replies.