Woocommerc rename field name in admin Customer billing address - woocommerce

How to rename of label "Phone" in admin area of Customer billing address?

You need to use woocommerce_customer_meta_fields filter.
add_filter( 'woocommerce_customer_meta_fields', 'filter_add_customer_meta_fields', 10, 1 );
function filter_add_customer_meta_fields( $args ) {
$args['billing']['fields']['billing_phone'] = array(
'label' => __( 'My custom text', 'woocommerce' ),
);
return $args;
}

Related

How to add phone number masking in woo commerce my account page in wordpress [duplicate]

This question already has an answer here:
Add a mobile phone field on My account > edit account in Woocommerce
(1 answer)
Closed 6 months ago.
I want to add phone number masking on my account page of Woocommerce in wordpress?
Add the below code snippet in your active theme's functions.php file -
// Add field in Account Details
function wc_add_field_edit_account_form() {
woocommerce_form_field(
'user_phone_number',
array(
'type' => 'tel',
'required' => true, // for false do not need this `woocommerce_save_account_details_required_fields` callback
'label' => __( 'Phone Number', 'yourtextdomain' ),
),
get_user_meta( get_current_user_id(), 'user_phone_number', true )
);
}
add_action( 'woocommerce_edit_account_form', 'wc_add_field_edit_account_form' );
// Save field data
function wc_save_account_details( $user_id ) {
update_user_meta( $user_id, 'user_phone_number', wc_clean( $_POST[ 'user_phone_number' ] ) );
}
add_action( 'woocommerce_save_account_details', 'wc_save_account_details' );
// Add field required
function wc_add_account_details_required_fields( $required_fields ){
$required_fields[ 'user_phone_number' ] = __( 'Phone Number', 'yourtextdomain' );
return $required_fields;
}
add_filter( 'woocommerce_save_account_details_required_fields', 'wc_add_account_details_required_fields' );

How do I get the "text" value from a dropdown list as an email notification? [duplicate]

This question already has answers here:
Order custom fields not displayed on WooCommerce email notifications
(2 answers)
Show the result of custom delivery field on the checkout page in WooCommerce frontend, backend & email notifications
(1 answer)
Closed 8 months ago.
Thanks to some help, I've created a dropdown list on the checkout page of my Woocommerce site. It works beautifully but on my email notification, it shows the code and not the value of the selection. Eg: "My Marketer: mariaMarais" instead of "My Marketer: Maria Marais - Natal." How can I change it to show the string and not the code?
// add marketer list
//* Add select field to the checkout page
add_action('woocommerce_before_order_notes', 'dd_add_select_two_checkout_field');
function dd_add_select_two_checkout_field( $checkout ) {
woocommerce_form_field( 'myquestion', array(
'type' => 'select',
'class' => array( 'select2-wrapper' ),
'label' => __( 'Please select your marketer.' ),
'required' => true,
'input_class' => array( 'add-select2' ),
'options' => array( // added extra for effect.
'headoffice' => __( 'Head Office', 'wps' ),
'mariaMarais' => __( 'Maria Marais - Natal', 'wps' )
)
),
$checkout->get_value( 'myquestion' ));
wc_enqueue_js( "$( '.add-select2' ).selectWoo(); ");
}
//* Update the order meta with field value
add_action('woocommerce_checkout_update_order_meta', 'wps_select_checkout_field_update_order_meta');
function wps_select_checkout_field_update_order_meta( $order_id ) {
if ($_POST['myquestion']) update_post_meta( $order_id, 'myquestion', esc_attr($_POST['myquestion']));
}
//* Display field value on the order edition page
add_action( 'woocommerce_admin_order_data_after_billing_address', 'wps_select_checkout_field_display_admin_order_meta', 10, 1 );
function wps_select_checkout_field_display_admin_order_meta($order){
echo '<p><strong>'.__('Found by').':</strong> ' . get_post_meta( $order->id, 'myquestion', true ) . '</p>';
}
//* Add selection field value to emails
add_filter('woocommerce_email_order_meta_keys', 'wps_select_order_meta_keys');
function wps_select_order_meta_keys( $keys ) {
$keys['My Marketer:'] = 'myquestion';
return $keys;
}

Add checkbox to product inventory tab in WooCommerce and have the checkbox checked by default

I got this snippet in here to add checkbox custom field which is auto set and it’s working fine.
// Displaying quantity setting fields on admin product pages
add_action( 'woocommerce_product_options_pricing', 'add_custom_field_product_options_pricing' );
function add_custom_field_product_options_pricing() {
global $product_object;
echo '</div><div class="options_group">';
$values = $product_object->get_meta('_cutom_meta_key');
woocommerce_wp_checkbox( array( // Checkbox.
'id' => '_cutom_meta_key',
'label' => __( 'Custom label', 'woocommerce' ),
'value' => empty($values) ? 'yes' : $values,
'description' => __( 'Enable this to make something.', 'woocommerce' ),
) );
}
// Save quantity setting fields values
add_action( 'woocommerce_admin_process_product_object', 'save_custom_field_product_options_pricing' );
function save_custom_field_product_options_pricing( $product ) {
$product->update_meta_data( '_cutom_meta_key', isset($_POST['_cutom_meta_key']) ? 'yes' : 'no');
}
My question: how to move this checkbox to be on the inventory tab and have the checkbox checked by default?
I’ve tried changing :
add_action( 'woocommerce_product_options_pricing', 'add_custom_field_product_options_pricing' );
to:
add_action( 'woocommerce_product_options_inventory_product_data', 'add_custom_field_product_options_pricing' );
AND
add_action( 'woocommerce_admin_process_product_object', 'save_custom_field_product_options_pricing' );
to:
add_action( 'woocommerce_process_product_meta', 'save_custom_field_product_options_pricing' );
But to no avail. Any advice?
woocommerce_admin_process_product_object replaces the outdated woocommerce_process_product_meta hook so you should definitely not replace it with it
To have the checkbox checked by default you can add value to the args from woocommerce_wp_checkbox()
So you get:
// Add checkbox
function action_woocommerce_product_options_inventory_product_data() {
global $product_object;
// Get meta
$value = $product_object->get_meta( '_cutom_meta_key' );
// Checkbox
woocommerce_wp_checkbox( array(
'id' => '_cutom_meta_key', // Required, it's the meta_key for storing the value (is checked or not)
'label' => __( 'Custom label', 'woocommerce' ), // Text in the editor label
'desc_tip' => false, // true or false, show description directly or as tooltip
'description' => __( 'Enable this to make something', 'woocommerce' ), // Provide something useful here
'value' => empty( $value ) ? 'yes' : $value // Checked by default
) );
}
add_action( 'woocommerce_product_options_inventory_product_data', 'action_woocommerce_product_options_inventory_product_data', 10, 0 );
// Save Field
function action_woocommerce_admin_process_product_object( $product ) {
// Update meta
$product->update_meta_data( '_cutom_meta_key', isset( $_POST['_cutom_meta_key'] ) ? 'yes' : 'no' );
}
add_action( 'woocommerce_admin_process_product_object', 'action_woocommerce_admin_process_product_object', 10, 1 );

Add new order status and send email notification woocommerce [duplicate]

This question already has answers here:
Add custom order status and send email on status change in Woocommerce
(1 answer)
Display orders with a custom status for "all" in Woocommerce admin orders list
(1 answer)
Closed 4 years ago.
Add shipped status on order status change and when status changed to shipped email notification will be send to billing email address.
I tried more and more articles, Please help. I need more explanation from this one.
Please use below code in your functions.php
Register Shipped Order Status in WooCommerce
/**
* Add custom status to order list
*/
add_action( 'init', 'register_custom_post_status', 10 );
function register_custom_post_status() {
register_post_status( 'wc-shipped', array(
'label' => _x( 'Shipped', 'Order status', 'woocommerce' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Shipped <span class="count">(%s)</span>', 'Shipped <span class="count">(%s)</span>', 'woocommerce' )
) );
}
/**
* Add custom status to order page drop down
*/
add_filter( 'wc_order_statuses', 'custom_wc_order_statuses' );
function custom_wc_order_statuses( $order_statuses ) {
$order_statuses['wc-shipped'] = _x( 'Shipped', 'Order status', 'woocommerce' );
return $order_statuses;
}
Here is the code for ending email to custom order status
add_action('woocommerce_order_status_changed', 'shipped_status_custom_notification', 10, 4);
function shipped_status_custom_notification( $order_id, $from_status, $to_status, $order ) {
if( $order->has_status( 'shipped' )) {
// Getting all WC_emails objects
$email_notifications = WC()->mailer()->get_emails();
// Customizing Heading and subject In the WC_email processing Order object
$email_notifications['WC_Email_Customer_Processing_Order']->heading = __('Your Order shipped','woocommerce');
$email_notifications['WC_Email_Customer_Processing_Order']->subject = 'Your {site_title} order shipped receipt from {order_date}';
// Sending the customized email
$email_notifications['WC_Email_Customer_Processing_Order']->trigger( $order_id );
}
}
add_action( 'woocommerce_order_status_wc-shipped', array( WC(), 'send_transactional_email' ), 10, 1 );
add_filter( 'woocommerce_email_actions', 'filter_woocommerce_email_actions' );
function filter_woocommerce_email_actions( $actions ){
$actions[] = 'woocommerce_order_status_wc-shipped';
return $actions;
}

Woocommerce order formatted billing address reorder and custom billing field

Thanks to the filter "WooCommerce admin billing fields" I have ordered the billing fields in the notificiación footer by email but when I try to insert my custom billing field does not appear.
add_filter( 'woocommerce_order_formatted_billing_address' , 'woo_reorder_billing_fields', 10, 2 );
function woo_reorder_billing_fields( $address, $wc_order ) {
$address = array(
'first_name' => $wc_order->billing_first_name,
'last_name' => $wc_order->billing_last_name,
'company' => $wc_order->billing_company,
'my_field' => $wc_order->billing_my_field,
'country' => $wc_order->billing_country
);
return $address;
}
In order admin edit I can show my custom billing field thanks to the filter "woocommerce_admin_billing_fields", first adding the field and then reordering the Array.
I note that I added before and I have reordered this field in my checkout with the filter "woocommerce_checkout_fields".
Why not show my custom field if "$ wc_order" object stores the field in the checkout?
Any ideas?
Thanks in advance!
Yes, here the explanation:
We will register the new cusotm field, in this example the field "VAT" to store the fiscal document for companies in the European Union. There is a lot of documentation on how to register the custom fields and display them in the admin / user panel.
add_filter( 'woocommerce_default_address_fields', 'woo_new_default_address_fields' );
function woo_new_default_address_fields( $fields ) {
$fields['vat'] = array(
'label' => __( 'VAT number', 'woocommerce' ),
'class' => array( 'form-row-wide', 'update_totals_on_change' ),
);
return $fields;
}
Then add the new field "VAT" only to the registration of billing fields for mails, we do not want it to appear in the address fileds section.
add_filter( 'woocommerce_order_formatted_billing_address' , 'woo_custom_order_formatted_billing_address', 10, 2 );
function woo_custom_order_formatted_billing_address( $address, $WC_Order ) {
$address = array(
'first_name' => $WC_Order->billing_first_name,
'last_name' => $WC_Order->billing_last_name,
'vat' => $WC_Order->billing_vat,
'company' => $WC_Order->billing_company,
'address_1' => $WC_Order->billing_address_1,
'address_2' => $WC_Order->billing_address_2,
'city' => $WC_Order->billing_city,
'state' => $WC_Order->billing_state,
'postcode' => $WC_Order->billing_postcode,
'country' => $WC_Order->billing_country
);
return $address;
}
The following code customizes the appearance of the addresses, this is where we must add the call to the new VAT field. This allows us to customize the address view for each country independently.
add_filter( 'woocommerce_formatted_address_replacements', function( $replacements, $args ){
$replacements['{vat}'] = $args['vat'];
return $replacements;
}, 10, 2 );
add_filter( 'woocommerce_localisation_address_formats' , 'woo_includes_address_formats', 10, 1);
function woo_includes_address_formats($address_formats) {
$address_formats['ES'] = "{name}\n{company}\n{vat}\n{address_1}\n{address_2}\n{postcode} {city}\n{state}\n{country}";
$address_formats['default'] = "{name}\n{company}\n{vat}\n{nif}\n{address_1}\n{address_2}\n{city}\n{state}\n{postcode}\n{country}";
return $address_formats;
}
Any questions ask!

Resources