Change title "Additional Information" in woocommerce - wordpress

I want to change the title from the checkout page. But I just can change the label and the placeholder.
// Hook in
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['order']['order_comments']['placeholder'] = 'Please type your PO number here and we will add it to the invoice.';
$fields['order']['order_comments']['label'] = '';
return $fields;
}

https://docs.woocommerce.com/document/editing-product-data-tabs/#
/**
* Rename product data tabs
*/
add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );
function woo_rename_tabs( $tabs ) {
$tabs['description']['title'] = __( 'More Information' ); // Rename the description tab
$tabs['reviews']['title'] = __( 'Ratings' ); // Rename the reviews tab
$tabs['additional_information']['title'] = __( 'Product Data' ); // Rename the additional information tab
return $tabs;
}

As it stands there is not hook to change the section title. But here's the hack if you are desperate enough to make the modification.
Locate your template folder
Create a folder named 'checkout'
Locate the file form-shipping.php in the Woocommerce plugin foler under templates/checkout/
Copy file in step 3 to the folder created in step 2
Now you have superpowers over the checkout form
Edit this line:
<h3><?php _e( 'Additional Information', 'woocommerce' ); ?></h3>

This solution worked for me:
function ajg_relabel_additional_information_tab(){
return __( 'Specification', 'text-domain' );
}
add_filter('woocommerce_product_additional_information_heading', 'ajg_relabel_additional_information_tab');

function th_wc_order_review_strings( $translated_text, $text, $domain ) {
if(is_checkout()){
switch ($translated_text) {
case 'Billing details' :
$translated_text = __( 'Billing Info', 'woocommerce' );
break;
case 'Additional information':
$translated_text = __('New Field Name', 'woocommerce');
break;
case 'Your order':
$translated_text = __('My Order', 'woocommerce');
break;
case 'Product':
$translated_text = __('Your Product', 'woocommerce');
break;
}
}
return $translated_text;
}
add_filter( 'gettext', 'th_wc_order_review_strings', 20, 3 );

The documentation of Woocommerce is not complety...
https://docs.woocommerce.com/document/editing-product-data-tabs/
You would check condition about the callback before add or replace some value in array, otherwise the tab will display with nothing inside.
/**
* Filter product data tabs
*/
function filter_product_tabs( $tabs ) {
global $product;
if ( isset($tabs['description']['callback']) ) {
$tabs['description']['title'] = __( 'More Information' ); // Rename the description tab
$tabs['description']['priority'] = 5; // Description
}
if ( isset($tabs['additional_information']['callback']) ) {
$tabs['additional_information']['title'] = __( 'Product Data' ); // Rename the additional information tab
$tabs['additional_information']['priority'] = 10; // Additional information
}
if ( isset($tabs['reviews']['callback']) ) {
$tabs['reviews']['title'] = __( 'Review' ) . ' (' . $product->get_review_count() . ') '; // Rename the reviews tab
$tabs['reviews']['priority'] = 15; // Reviews
}
return $tabs;
}
add_filter( 'woocommerce_product_tabs', 'filter_product_tabs', 98 );
Why ? because the developper Woocommerce will check the content of array in the tab template
(version 3.8.0) (WC
/**
* Filter tabs and allow third parties to add their own.
*
* Each tab is an array containing title, callback and priority.
*
* #see woocommerce_default_product_tabs()
*/
$product_tabs = apply_filters( 'woocommerce_product_tabs', array() );
if ( ! empty( $product_tabs ) ) :
....

This worked for me if anyone is still after this change
//Shipping Weight custom tab name
add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );
function woo_rename_tabs( $tabs ) {
$tabs['additional_information']['title'] = __( 'Additional Information' ); // Rename the Additional Information text
return $tabs;
}

Related

Create a custom field on WooCommerce checkout if product category equals x

so I'm looking to create/show a couple of custom fields on the checkout page of my WooCommerce page as long as a product with a certain category is in the cart. The values of these fields are only necessary for me to access in the order on the backend afterwards, and does not need to be added to the order e-mail confirmation to the customer.
Any pointers? If it helps things, I'm using ACF on my website.
Thanks in advance!
You need to do the following:
Detect if the existing products in cart is in your category
Add the fields on checkout if it matches your condition.
Validate and save the data
Display it on the backend.
This is already outlined on the docs, and you might want to read it:
https://woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/#adding-a-custom-special-field
Here is an example function to detect if the cart contains a certain product within a defined category
// functions.php
function cat_in_cart( $cat_slug ) {
$cat_in_cart = false;
$cart = WC()->cart->get_cart();
if ( !$cart ) {
return $cat_in_cart;
}
foreach( $cart as $cart_item_key => $cart_item ) {
if ( has_term( $cat_slug, 'product_cat', $cart_item['product_id'] )) {
$cat_in_cart = true;
break;
}
}
return $cat_in_cart;
}
To add a field on checkout (Link to docs):
// functions.php
/**
* Add the field to the checkout
*/
add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
function my_custom_checkout_field( $checkout ) {
if ( cat_in_cart( 'your_category_slug' ) ) {
echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';
woocommerce_form_field( 'my_field_name', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Fill in this field'),
'placeholder' => __('Enter something'),
), $checkout->get_value( 'my_field_name' ));
echo '</div>';
}
}
After that, save the field on checkout:
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
function my_custom_checkout_field_process() {
// Check if set, if its not set add an error.
if ( ! $_POST['my_field_name'] )
wc_add_notice( __( 'Please enter something into this new shiny field.' ), 'error' );
}
add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta' );
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST['my_field_name'] ) ) {
update_post_meta( $order_id, 'My Field', sanitize_text_field( $_POST['my_field_name'] ) );
}
}
Lastly, display it on the dashboard:
/**
* Display field value on the order edit page
*/
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo '<p><strong>'.__('My Field').':</strong> ' . get_post_meta( $order->id, 'My Field', true ) . '</p>';
}

Woocommerce Change "Select option" text in variable product page

On product page 'dropdown) i'd like to modify the SELECT OPTIONS text and i assume this code could to this but nothing change in my page even if i empty cache.
Thanks for your help
add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );
function custom_woocommerce_product_add_to_cart_text() {
global $product;
$product_type = $product->product_type;
switch ( $product_type ) {
case 'variable':
return __( 'Options', 'woocommerce' );
break;
}
}
Use the following code --
add_filter('woocommerce_dropdown_variation_attribute_options_args', 'custom_woocommerce_product_add_to_cart_text', 10, 2);
function custom_woocommerce_product_add_to_cart_text($args){
$args['show_option_none'] = __( 'Options', 'woocommerce' );
return $args;
}
I'm little late but below code can also be used .
add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );
function custom_woocommerce_product_add_to_cart_text() {
global $product;
$product_type = $product->product_type;
switch ( $product_type ) {
case 'variable':
return __( 'Options', 'woocommerce' );
break;
}
case 'simple':
return __( 'Purchase', 'woocommerce' );
break;
}
}
Reference : https://www.raadeen.com/change-select-options-text-woocommerce/

Hide / Change WooCommerce admin notice

Hi WooCommerce ninjas!
I'm developing WooCommerce plugin and every time when I submit form (Save Changes button) on top shows update notice with 'Your settings have been saved.'. How I can hide or change this notice, I'm use woocommerce_show_admin_notice filter but don't work in my plugin class. Below is part of code from my plugin. Any ideas for hook who will be usefull?
Great thanks!
<?php
class name_of_plugin extends WC_Payment_Gateway {
public $error = '';
// Setup our Gateway's id, description and other values
function __construct() {
$this->id = "name_of_plugin";
$this->method_title = __( "Name", 'domain' );
$this->method_description = __( "Gateway Plug-in for WooCommerce", 'domain' );
$this->title = __( "TFS VPOS", 'domain' );
$this->icon = null;
$this->has_fields = false;
$this->init_settings();
$this->init_form_fields();
$this->title = $this->get_option( 'title' );
$this->testurl = 'https://example.com/payment/api';
$this->liveurl = 'https://example.com/payment/api';
// Save settings
if ( is_admin()) {
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
}
// Disable Admin Notice
add_filter( 'woocommerce_show_admin_notice', array( $this, 'shapeSpace_custom_admin_notice' ), 10, 2 );
// add the filter
add_filter( 'woocommerce_add_error', array( $this, 'filter_woocommerce_add_notice_type' ), 10, 1 );
} // End __construct()
// display custom admin notice
public function filter_woocommerce_add_notice_type($true, $notice ) {
// magic happen here...
return $true;
}
I can't see any proper hook that can be used to remove this.
But these 2 seems to work.
My first thought is to reload the page so the settings text will be gone at the time. Something like this.
add_action( 'woocommerce_sections_checkout', 'woocommerce_sections_checkout' );
function woocommerce_sections_checkout() {
if ( isset( $_GET['section'] ) && isset( $_REQUEST['_wpnonce'] ) && ( $_GET['section'] === 'paypal' )
&& wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-settings' ) ) {
WC_Admin_Settings::add_message( __( 'Your settings have been saved!', 'woocommerce' ) );
wp_safe_redirect( wp_get_raw_referer() );
exit();
}
}
Then my second option is if you wanted to change the text, we can use the filter gettext.
add_filter( 'gettext', 'woocommerce_save_settings_text', 20, 3 );
function woocommerce_save_settings_text( $translated_text, $text, $domain ) {
if ( ( $domain == 'woocommerce' ) && isset( $_GET['section'] ) && ( $_GET['section'] === 'paypal' ) ) {
switch ( $translated_text ) {
case 'Your settings have been saved.' :
$translated_text = __( 'Your awesome settings have been saved.', 'woocommerce' );
break;
}
}
return $translated_text;
}
Please do note that this code is just an example and will work for paypal settings. Change everything that is needed.

Modify woocommerce orders.php columns

I am trying to modify the columns in the Woocommerce orders.php table. I would like to get rid of the TOTAL column as well as the DATE column and then I would like to add a new column with some custom information that’s specific to my store.
The following function used to work but has been deprecated since Woocommerce 2.6. So the question is, does anybody know how to delete/add columns to this table after 2.6?
function wc_get_account_orders_columns() {
$columns = apply_filters( 'woocommerce_account_orders_columns', array(
'order-number' => __( 'Order', 'woocommerce' ),
'order-date' => __( 'Date', 'woocommerce' ),
'order-status' => __( 'Status', 'woocommerce' ),
'order-total' => __( 'Total', 'woocommerce' ),
'order-actions' => ' ',
) );
// Deprecated filter since 2.6.0.
return apply_filters( 'woocommerce_my_account_my_orders_columns', $columns );
}
A friend of mine helped me out with this. Here is the function that I ended up using in case anybody finds it useful:
function new_orders_columns( $columns = array() ) {
// Hide the columns
if( isset($columns['order-total']) ) {
// Unsets the columns which you want to hide
unset( $columns['order-number'] );
unset( $columns['order-date'] );
unset( $columns['order-status'] );
unset( $columns['order-total'] );
unset( $columns['order-actions'] );
}
// Add new columns
$columns['order-number'] = __( 'Reserva', 'Text Domain' );
$columns['reservation-date'] = __( 'Para el día', 'Text Domain' );
$columns['reservation-people'] = __( 'Seréis', 'Text Domain' );
$columns['order-status'] = __( 'Estado de la reserva', 'Text Domain' );
$columns['order-actions'] = __( ' ', 'Text Domain' );
return $columns;
}
add_filter( 'woocommerce_account_orders_columns', 'new_orders_columns' );
Note that it is not necesary to first unset all the columns and then set them again like I did unless you want to change the order in which they apear or insert new columns between the existing ones.
In the other answers it is not mentioned how to populate a column with custom information. So, the complete algorithm is below:
Step 1. Add or remove
add_filter( 'manage_edit-shop_order_columns','your_function_name');
function your_function_name($columns)
{
// to remove just use unset
unset($columns['order_total']); // remove Total column
unset($columns['order_date']); // remove Date column
// now it is time to add a custom one
$columns['custom_column'] = "Column title";
return $columns;
}
Step 2. Fill with data
add_action( 'manage_shop_order_posts_custom_column' , 'your_function_name2' );
function your_function_name2( $column ) {
global $the_order; // you can use the global WP_Order object here
// global $post; // is also available here
if( $column == 'custom_column' ) {
// do stuff, ex: get_post_meta( $post->ID, 'key', true );
}
}
You can also check this tutorial for more examples.
This will help you.
add_filter( 'manage_edit-shop_order_columns','your_function_name',10 );
function your_function_name($columns)
{
unset($columns['order_total']);
unset($columns['order_date']);
return $columns;
}

WooCommerce show custom column

I want to show a additional column in the backend of WooCommerce (in Orders overview).
The column should contain a custom field, which i have defined (delivery date).
How to do this?
In case someone still needs it - instructions on how to add new columns in Woocommerce orders list. No need in unsetting the default columns, just add this in your functions.php and your code will be valid for updates.
1. Define columns position and names
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;
}
2. For each custom column, show the values
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'] : '');
}
//stop editing
}
3. (optional) Function to make the columns sortable
add_filter( "manage_edit-shop_order_sortable_columns", 'MY_COLUMNS_SORT_FUNCTION' );
function MY_COLUMNS_SORT_FUNCTION( $columns ) {
$custom = array(
//start editing
'MY_COLUMN_ID_1' => 'MY_COLUMN_1_POST_META_ID',
'MY_COLUMN_ID_2' => 'MY_COLUMN_2_POST_META_ID'
//stop editing
);
return wp_parse_args( $custom, $columns );
}
To add new column coupon in woo-commerce order table and get all coupon code according to order. you need to copy and paste in you function.php.
add_filter('manage_edit-shop_order_columns', 'custom_shop_order_column', 11);
function custom_shop_order_column($columns) {
//add columns
$columns['my-column1'] = __('Coupons Code', 'theme_slug');
return $columns;
}
// adding the data for each orders by column (example)
add_action('manage_shop_order_posts_custom_column', 'cbsp_credit_details', 10, 2);
function cbsp_credit_details($column) {
global $post, $woocommerce, $the_order;
$order_id = $the_order->id;
switch ($column) {
case 'my-column1' :
// $myVarOne = wc_get_order_item_meta( $order_id, 15, true );
if ($the_order->get_used_coupons()) {
$coupons_count = count($the_order->get_used_coupons());
foreach ($the_order->get_used_coupons() as $coupon) {
echo $coupon;
$i++;
}
echo '</p>';
}
// echo $myVarOne;
break;
}
}
Try this, you will get your solution just write below code on your function.php file.
add_filter( 'manage_edit-shop_order_columns','your_function_name',10 );
function your_function_name($columns){
$columns['delivery_date'] = __('Delivery date','textdomain');
return $columns;
}
add_action( 'manage_shop_order_posts_custom_column','your_other_function_name',20 );
function your_other_function_name($column)
{
swith($column)
{
case 'delivery_date': // your custom code here and do what you want.
}
}
The following works for WooCommerce 2.6.2.
You should look into two new hooks:
woocommerce_admin_order_item_headers, invoked once when orders table header is generated
woocommerce_admin_order_item_values, invoked once per every item inside the order
1. Define columns headers
add_filter('woocommerce_admin_order_item_headers', 'so13683162_headers');
function so13683162_headers($order) {
echo "<th>FIELD1</th>";
}
2. Populate values in rows
add_filter('woocommerce_admin_order_item_values', 'so13683162_values');
function so13683162_values($product) {
if (isset($product -> id)) {
$attrs = get_post_meta($product -> id, "_product_attributes", true);
echo "<td>" . $attrs["FIELD1"]["value"] . "</td>";
}
}
I came across Woocommerce now. Have added a custom field Personal Registration Number - and now wanted it to be displayed in the Order overview page.
I've manage to add the column - but still couldn't get the value of the custom field for each order.
Here is what I did:
// Removed Existing Order Page collumns
remove_filter('manage_edit-shop_order_columns', 'woocommerce_edit_order_columns');
// Added My own filter to Show the PRN - Personal Registration field
add_filter('manage_edit-shop_order_columns', 'omak_edit_order_columns');
// The omak_edit_order_columns definition
/*** Taken from admin/post_types/shop_order.php ***/
function omak_edit_order_columns($columns){
global $woocommerce;
$columns = array();
$columns["cb"] = "<input type=\"checkbox\" />";
$columns["order_status"] = __( 'Status', 'woocommerce' );
$columns["order_title"] = __( 'Order', 'woocommerce' );
$columns["order_prn"] = __( 'PRN', 'woocommerce' ); // This is the line which added the column after the Title Column
$columns["billing_address"] = __( 'Billing', 'woocommerce' );
$columns["shipping_address"] = __( 'Shipping', 'woocommerce' );
$columns["total_cost"] = __( 'Order Total', 'woocommerce' );
$columns["order_comments"] = '<img alt="' . esc_attr__( 'Order Notes', 'woocommerce' ) . '" src="' . $woocommerce->plugin_url() . '/assets/images/order-notes_head.png" class="tips" data-tip="' . __( 'Order Notes', 'woocommerce' ) . '" width="12" height="12" />';
$columns["note"] = '<img src="' . $woocommerce->plugin_url() . '/assets/images/note_head.png" alt="' . __( 'Customer Notes', 'woocommerce' ) . '" class="tips" data-tip="' . __( 'Customer Notes', 'woocommerce' ) . '" width="12" height="12" />';
$columns["order_date"] = __( 'Date', 'woocommerce' );
$columns["order_actions"] = __( 'Actions', 'woocommerce' );
return $columns;
}
Let me know if it helps you...
I am left to deal with how to get its values for each Order.
As commented: the function definition exists in shop_order.php in WooCommerce plugin.
Let me know if anybody sorts it out.. or knows how to do it.
Thanks,
(sorry, was busy in something so couldn't read back to check for errors)

Resources