I am using woocommerce with flatsome theme. My website is in Spanish, and I am quite happy with how its translated automatically, but I have one issue. The checkout has the breadcrumbs in English. Any way I can add a snippet to change;
Shopping cart -> Carrito
Checkout details -> Detalles de pago
Order complete -> Pedido completado
Thanks
Ok, I found out how to do it, I hope this can help someone else;
add_filter( 'gettext', function ( $strings ) {
/**
* Holding translations/changes.
* 'to translate' => 'the translation or rewording'
*/
$text = array(
'SHOPPING CART' => 'CARRITO',
'CHECKOUT DETAILS' => 'DETALLES DE PAGO',
'ORDER COMPLETE' => 'PAGO COMPLETADO',
);
$strings = str_ireplace( array_keys( $text ), $text, $strings );
return $strings;
}, 20 );
Related
I'm currently using the porto theme on wordpress with woocommerce, and it doesn't have an option to show the product description in the mini cart or checkout page. I was able to find the following css code to add that worked, but I'm trying to limit this to display the product descriptions for most products while excluding only items from one specific category slug.
For example, we have cart items and would like the description to be hidden only for the pats in that one category 'carts'. Here's the code I found that blanket worked for every product.
add_filter( 'woocommerce_get_item_data', 'customizing_cart_item_data', 10, 2 );
function customizing_cart_item_data( $cart_data, $cart_item ) {
$description = $cart_item['data']->get_description(); // Get the product description
// For product variations when description is empty
if( $cart_item['variation_id'] > 0 && empty( $description ) ){
// Get the parent variable product object
$parent_product = wc_get_product( $cart_item['product_id'] );
// Get the variable product description
$description = $parent_product->get_description();
}
// If product or variation description exists we display it
if( ! empty( $description ) ){
$cart_data[] = array(
'key' => __( 'Description', 'woocommerce' ),
'value' => $description,
'display' => $description,
);
}
return $cart_data;
}
Does anyone have a recommendation? Thanks in advance I really appreciate it!
Possibly just insert the following in the function before processing anything else:
if ( has_term( 'your-slug', 'product_cat', $cart_item ) ) {
return $cart_data ;
}
See https://developer.wordpress.org/reference/functions/has_term/
Actually, I'm working on woocommerce customization...
I've read this question about the title change in metabox:
Customizing WooCommerce Short Description Metabox title
It help me a lot. But, in the product, how can I find the "metabox tag" callback name?
function epptm_rename_meta_boxes(){
remove_meta_box( 'tagsdiv-product_tag', 'product', 'side' );
add_meta_box( 'tagsdiv-product_tag', __( 'This metabox is awesome', 'your-plugin' ), 'CALLBACK?', 'product', 'side' );
}
add_action( 'add_meta_boxes', 'epptm_rename_meta_boxes', 40 );
here is another solution found:
/**
* hook to the 'add_meta_boxes' action to modify title
*/
function change_meta_box_titles() {
global $wp_meta_boxes; // array of defined meta boxes
// cycle through the array, change the titles you want
$wp_meta_boxes['product']['side']['core']['tagsdiv-product_tag']['title']= 'Here is my new title';
}
add_action('add_meta_boxes', 'change_meta_box_titles');
I have the following code added on my theme's functions.php file, in order to translate some rebel strings I was unable to translate by the ordinary way / plugins:
function wc_billing_field_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Billing Address' :
$translated_text = __( 'Detalles de facturación', 'woocommerce' );
break;
case 'Shipping Address' :
$translated_text = __( 'Dirección de envío', 'woocommerce' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'wc_billing_field_strings', 20, 3 );
Now I have installed WPML and I need this code to run only when the languaje is Spanish.
ICL_LANGUAGE_CODE contain current language https://wpml.org/documentation/support/wpml-coding-api/
But, if you already using WPML — why you don't get rid of this code at all and translate all string inside WPML admin?
i want to make this change to my site.
after adding product in cart, i want to integrate more buttons in that notice showed in image. I want inside to place button:
Continue Shopping and Finish Shopping buttons .
How to do this? i searched on google and found some functions for this, but none of them was ok for my needs. This is one of them:
/**
* Custom Add To Cart Messages
* Add this to your theme functions.php file
**/
add_filter( 'wc_add_to_cart_message', 'custom_add_to_cart_message' );
function custom_add_to_cart_message() {
global $woocommerce;
// Output success messages
if (get_option('woocommerce_cart_redirect_after_add')=='yes') :
$return_to = get_permalink(woocommerce_get_page_id('shop'));
$message = sprintf('%s %s',
$return_to, __('Continue Shopping →', 'woocommerce'), __('Product
successfully added to your cart.', 'woocommerce') );
else :
$message = sprintf('%s %s',
get_permalink(woocommerce_get_page_id('cart')), __('View Cart →',
'woocommerce'), __('Product successfully added to your cart.',
'woocommerce') );
endif;
return $message;
}
/* Custom Add To Cart Messages */
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;
}