How to edit the fields in Woocommerce? - php

Where is the .php file located to edit the billing fields?
I want to change the text for each heading; for example Last Name to Family Name.
This is using Woocommerce in the Avada theme.
I've managed to change the fields using this code, but city, state and postcode won't change:
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_first_name']['label'] = '名';
$fields['billing']['billing_last_name']['label'] = '姓';
$fields['billing']['billing_email']['label'] = 'メールアドレス';
$fields['billing']['billing_phone']['label'] = '電話番号';
$fields['billing']['billing_country']['label'] = '国';
$fields['billing']['billing_city']['label'] = '名!';
$fields['billing']['billing_city']['placeholder'] = '市町村';
$fields['billing']['billing_state']['label'] = '都道府県';
$fields['billing']['billing_state']['placeholder'] = '都道府県';
$fields['billing']['billing_postcode']['label'] = '郵便番号';
$fields['billing']['billing_postcode']['placeholder'] = '郵便番号';
$fields['billing']['billing_address_1']['label'] = '住所';
$fields['billing']['billing_address_1']['placeholder'] = '住所';
$fields['billing']['billing_address_2']['placeholder'] = 'アパート名等';
return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

Try increase your priority used:
add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields', 50 );

Related

Filter products by clickable value in custom column WooCommerce

We add a new column to display the author => store-name form each product. (Add custom meta column to WooCommerce product listing)
I was able to answer the mentioned question by my self. But now we ran into a new problem. The needed information are now in the new column, but we can not click it. We want to have the entries in that new column clickable in order that every product from that author would be filtered. So it's a question about how to make a clickable link in order to show all other product from that author.
This is our code:
add_filter( 'manage_edit-product_columns', 'custom_admin_products_store_name_column', 9999 );
function custom_admin_products_store_name_column( $columns ){
$columns['vendor_store_name'] = __( 'Vendor');
return $columns;
}
add_action( 'manage_product_posts_custom_column', 'custom_admin_products_store_name_column_content', 10, 2 );
function custom_admin_products_store_name_column_content( $column, $product_id ){
$seller = get_post_field( 'post_author', $product_id);
$store_info = dokan_get_store_info( $seller );
$store_name = $store_info['store_name'];
if ( $column == 'vendor_store_name' ) {
echo __($store_name);
}
}
I already tried around with the information from here: WooCommerce: Adding a custom filter to the Product Admin area
But this is more for a new filter than a clickable value in a column which will apply a filter.
I was able to get this to work! :)
Here is my code. Is this a proper solution or where can I improve this? :)
Thanlks
add_filter( 'manage_edit-product_columns', 'custom_admin_products_store_name_column', 9999 );
function custom_admin_products_store_name_column( $columns ){
$columns['vendor_store_name'] = __( 'Vendor');
return $columns;
}
add_action( 'manage_product_posts_custom_column', 'custom_admin_products_store_name_column_content', 10, 2 );
function custom_admin_products_store_name_column_content( $column, $product_id ){
$seller = get_post_field( 'post_author', $product_id);
$store_info = dokan_get_store_info( $seller );
$store_name = $store_info['store_name'];
$vendor_products = get_admin_url() . 'edit.php?post_type=product&author=' . $seller;
if ( $column == 'vendor_store_name' ) {
printf('%s', $vendor_products, $store_name);
}
}

Add some data to custom database table once WooCommerce order is placed

Please Guys,
i need to capture data from the checkout page form and save in a custom table.
1° i created a custom table: wp_personalinfo
2° below is the script that i'm using inside functions.php
/*
* Submit button name - 'woocommerce_checkout_place_order'
*/
if (!empty($_POST['woocommerce_checkout_place_order'])) {
/*
* Form Fields
*/
if (!empty($_POST['billing_first_name']) and
!empty($_POST['billing_last_name']) and
!empty($_POST['billing_phone']) and
!empty($_POST['billing_recommend']) and
!empty($_POST['billing_email'])) {
// DB Class Connection
global $wpdb;
// Sanitize the fields - form checkout.php
$billing_first_name = sanitize_text_field($_POST['billing_first_name']);
$billing_last_name = sanitize_text_field($_POST['billing_last_name']);
$billing_phone = sanitize_text_field($_POST['billing_phone']);
$billing_recommend = sanitize_text_field($_POST['billing_recommend']);
$billing_email = sanitize_text_field($_POST['billing_email']);
// Prefix db
$tablepsl = $wpdb->prefix.'personalinfo';
$datapsl = array(
'TB_NAME' => $billing_first_name,
'TB_LAST_NAME' => $billing_last_name,
'TB_PHONE' => $billing_phone,
'TB_RECOMENDATION' => $billing_recommend,
'TB_EMAIL' => $billing_email
);
$wpdb->insert($tablepsl, $datapsl);
} else {
echo 'All fields are mandatory';
}
}
No data it's been saved in the table wp_personalinfo.
What am i doing wrong please?
have you tried var_dump($_POST)
can be hook woocommerce_checkout_place_order not working
let to try on hook woocommerce_checkout_process
Well, Today is 21.10.2020 02:43 PM and i use the current woocommerce version is 4.6.0
This is what works for me.:
function porto_woocommerce_checkout_create_order( $order, $data ) {
$order = $order->save();
$billing_first_name = sanitize_text_field($data['billing_first_name']);
$billing_last_name = sanitize_text_field($data['billing_last_name']);
$billing_recommend = sanitize_text_field($data['billing_recommend']);
$billing_phone = sanitize_text_field($data['billing_phone']);
$billing_email = sanitize_text_field($data['billing_email']);
$payment_method = sanitize_text_field($data['payment_method']);
//$order_number = sanitize_text_field($data['order_number']);
// Prefix db
global $wpdb;
$tablepsl = $wpdb->prefix . 'personalinfo';
$data = array(
'tb_name' => $billing_first_name,
'tb_lastname' => $billing_last_name,
'tb_recomendation' => $billing_recommend,
'tb_phone' => $billing_phone,
'tb_email' => $billing_email,
'tb_numorder_id' => $order
); $wpdb->insert($tablepsl, $data);
}
add_action( 'woocommerce_checkout_create_order', 'porto_woocommerce_checkout_create_order', 10, 2 );

Rearranging and customizing woocommerce checkout fields

I need to modify the default woocommerce billing&shipping fields. I need to move some of them, set a different form-row-class and add a placeholder while removing the labels. My code is working but I am wondering if there is a cleaner solution aka if the code can be shortened and/or optimized. my code is
add_filter('woocommerce_default_address_fields', 'override_address_fields');
function override_address_fields( $address_fields ) {
$address_fields['first_name']['placeholder'] = 'yxz';
$address_fields['last_name']['placeholder'] = 'yxz';
$address_fields['address_1']['placeholder'] = 'yxz';
$address_fields['company']['placeholder'] = 'yxz';
$address_fields['postcode']['placeholder'] = 'yxz';
$address_fields['city']['placeholder'] = 'yxz';
return $address_fields;
}
add_filter( "woocommerce_checkout_fields", "reordering_checkout_fields", 15, 1 );
function reordering_checkout_fields( $fields ) {
$fields['billing']['billing_phone']['placeholder'] = 'yxz';
$fields['billing']['billing_email']['placeholder'] = 'yxz';
unset($fields['order']['order_comments']);
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'rearrange_checkout_fields' );
function rearrange_checkout_fields( $checkout_fields ) {
$checkout_fields['billing']['billing_country']['priority'] = 80;
$checkout_fields['shipping']['shipping_country']['priority'] = 80;
return $checkout_fields;
}
You can include your third function in the first one, so your code will be like:
add_filter('woocommerce_default_address_fields', 'customize_default_address_fields', 20, 1 );
function customize_default_address_fields( $address_fields ) {
$address_fields['first_name']['placeholder'] = 'yxz';
$address_fields['last_name']['placeholder'] = 'yxz';
$address_fields['address_1']['placeholder'] = 'yxz';
$address_fields['company']['placeholder'] = 'yxz';
$address_fields['postcode']['placeholder'] = 'yxz';
$address_fields['city']['placeholder'] = 'yxz';
// Reorder billing and shipping "country" fields (on checkout page)
if ( is_checkout() )
$address_fields['country']['priority'] = 80; // Country
return $address_fields;
}
add_filter( "woocommerce_checkout_fields", "customize_other_checkout_fields", 20, 1 );
function customize_other_checkout_fields( $fields ) {
$fields['billing']['billing_phone']['placeholder'] = 'yxz';
$fields['billing']['billing_email']['placeholder'] = 'yxz';
$fields['billing']['billing_email']['class'] = array('form-row-first'); // HERE
$fields['billing']['billing_phone']['class'] = array('form-row-last'); // HERE
unset($fields['order']['order_comments']);
return $fields;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.

Clear shipping_*fields in WooCommerce Checkout

Trying to always have the "Ship to a different adress" cleared when a user is buying in WooCommerce Checkout. The following code is though doing aboslutely nothing. Does it have todo with cookies?
add_filter( 'woocommerce_checkout_get_value', 'remove_clear_checkout_shipping_fields', 10, 2 );
function remove_clear_checkout_shipping_fields( $value, $input ) {
if ( strpos( $input, 'shipping_' ) !== FALSE ) {
$value = '';
}
}
This way you can modify each field:
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['shipping']['shipping_first_name'] = '';
$fields['shipping']['shipping_last_name'] = '';
$fields['shipping']['shipping_company'] = '';
$fields['shipping']['shipping_address_1'] = '';
$fields['shipping']['shipping_address_2'] = '';
$fields['shipping']['shipping_city'] = '';
$fields['shipping']['shipping_postcode'] = '';
$fields['shipping']['shipping_country'] = '';
$fields['shipping']['shipping_state'] = '';
return $fields;
}
Just remove unnecessary fields.

How To add column on Woocommerce -> Orders backend page

Can't find working solution that would add an example column to backend Orders list. Already tried these (within child theme's functions.php):
add_filter('manage_edit-shop_order_columns', 'extra_column');
function extra_column($columns) {
$columns['title'] = 'Product-x';
return $columns;
}
add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' );
function MY_COLUMNS_FUNCTION($columns){
$new_columns = (is_array($columns)) ? $columns : array();
unset( $new_columns['order_actions'] );
//edit this for you column(s)
//all of your columns will be added before the actions column
$new_columns['MY_COLUMN_ID_1'] = 'MY_COLUMN_1_TITLE';
// $new_columns['MY_COLUMN_ID_2'] = 'MY_COLUMN_2_TITLE';
//stop editing
$new_columns['order_actions'] = $columns['order_actions'];
return $new_columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION', 2 );
function MY_COLUMNS_VALUES_FUNCTION($column){
global $post;
$data = get_post_meta( $post->ID );
//start editing, I was saving my fields for the orders as custom post meta
//if you did the same, follow this code
if ( $column == 'MY_COLUMN_ID_1' ) {
echo (isset($data['MY_COLUMN_1_POST_META_ID']) ? $data['MY_COLUMN_1_POST_META_ID'] : '');
}
if ( $column == 'MY_COLUMN_ID_2' ) {
echo (isset($data['MY_COLUMN_2_POST_META_ID']) ? $data['MY_COLUMN_2_POST_META_ID'] : '');
}
}
add_filter( 'manage_edit-shop_order_columns', 'imarcon_set_custom_column_order_columns');
function imarcon_set_custom_column_order_columns($columns) {
// global $woocommerce;
$nieuwearray = array();
foreach($columns as $key => $title) {
if ($key=='billing_address') // in front of the Billing column
$nieuwearray['order_producten'] = __( 'Products', 'woocommerce' );
$nieuwearray[$key] = $title;
}
return $nieuwearray ;
}
I am using WP 4.1.1, Avada 3.7.3 with Child Theme enabled, Gravity Forms 1.8.22 + few WooCommerce addons and other plugins.
OK got it - Woocommerce update solved it.

Categories