This solution is based on Add an informative custom message in Woocommerce Checkout page
I've created a custom message but not sure if the syntax is correct. It displays fine on the front end, but need help to check it.
add_action( 'woocommerce_before_checkout_form', 'print_webcache_notice', 10 );
function print_webcache_notice() {
wc_print_notice( sprintf(
__("Having trouble checking out? Please clear your web browser cache!", "woocommerce"),
'<strong>' . __("Information:", "woocommerce") . '</strong>',), 'success' );
}
There was a little missing thing in your sprintf() content (the placeholder):
add_action( 'woocommerce_before_checkout_form', 'print_webcache_notice', 10 );
function print_webcache_notice() {
wc_print_notice( sprintf(
__("%sHaving trouble checking out? Please clear your web browser cache!", "woocommerce"),
'<strong>' . __("Information:", "woocommerce") . '</strong> '
), 'success' );
}
or without using sprintf() function:
add_action( 'woocommerce_before_checkout_form', 'print_webcache_notice', 10 );
function print_webcache_notice() {
$message = '<strong>' . __("Information:", "woocommerce") . '</strong> ';
$message .= __("Having trouble checking out? Please clear your web browser cache!", "woocommerce");
wc_print_notice( $message, 'success' );
}
Both work.
Now if you don't need "Information:" string at the beginning, simply use:
add_action( 'woocommerce_before_checkout_form', 'print_webcache_notice', 10 );
function print_webcache_notice() {
wc_print_notice( __("Having trouble checking out? Please clear your web browser cache!", "woocommerce"), 'success' );
}
Related
for some reasons I want to change the links from “add to cart” buttons. So when on archive-product.php the link of this button should NOT got to the add-to-cart page but to the single-product page. (single-product.php)
When on single-product.php the button should link to another custom page I’ll define but also not to the add-to-cart page. (Which I don’t need for this use-case)
I realize, that this must be a conditional filter in functions.php – but I have no clue of how to make this.
I managed to change the Button texts depending on the page I am. Like:
function woocommerce_custom_single_add_to_cart_text() {
return __( 'Produkt verhindern', 'woocommerce' );
}
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' );
function woocommerce_custom_product_add_to_cart_text() {
return __( 'Mehr erfahren', 'woocommerce' );
}
To modify add to cart link to single product link in Archive page, please refer below code:
add_filter( 'woocommerce_loop_add_to_cart_link', 'replacing_add_to_cart_button', 10, 2 );
function replacing_add_to_cart_button( $button, $product ) {
$button_text = __("Add to cart", "woocommerce");
$button = '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
return $button;
}
To modify add to cart link to global another redirect link then below is the code:
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
add_action('woocommerce_single_product_summary', 'custom_single_add_to_cart', 30);
function custom_single_add_to_cart()
{
$button_text = __("Add to cart", "woocommerce");
echo '<a class="button" href="global_link_for_all_products">' . $button_text . '</a>';
}
I would like to change the "[Remove]" link text to an icon for coupons in WooCommerce checkout page.
Instead of "[Remove]" I would like it to be a trash can icon from Font Awesome.
I have found 2 code snippets to change the text:
function filter_woocommerce_cart_totals_coupon_html( $coupon_html, $coupon, $discount_amount_html ) {
// Change text
$coupon_html = $discount_amount_html . ' ' . __( '[Remove & Re-Calculate]', 'woocommerce' ) . '';
return $coupon_html;
}
add_filter( 'woocommerce_cart_totals_coupon_html', 'filter_woocommerce_cart_totals_coupon_html', 10, 3 );
OR
function filter_woocommerce_cart_totals_coupon_html( $coupon_html, $coupon, $discount_amount_html ) {
// Change text
$coupon_html = str_replace( '[Remove]', '[Remove & Re-Calculate]', $coupon_html );
return $coupon_html;
}
add_filter( 'woocommerce_cart_totals_coupon_html', 'filter_woocommerce_cart_totals_coupon_html', 10, 3 );
These code snippets allow me to change the text but I could not figure out how to add the icon. I would appreciate if someone could help me..
For example you can add a Font Awesome Icon using the following, on your 2nd code snippet:
function filter_woocommerce_cart_totals_coupon_html( $coupon_html, $coupon, $discount_amount_html ) {
// Change returned text
return str_replace( '[Remove]', ' [<i class="fas fa-minus-circle"></i> Remove & Re-Calculate]', $coupon_html );
}
add_filter( 'woocommerce_cart_totals_coupon_html', 'filter_woocommerce_cart_totals_coupon_html', 10, 3 );
Code goes in functions.php file of the active child theme (or active theme). It should work.
You will get in checkout page something like:
I am setting up a website based on Wordpress and Woocommerce can you tell me how can I change the Shopping Item in woocommerce. I want the title to be just "Cart".
I've tried to change it with add_action, but without success, even got an error.
add_action('cart-title', 'change-cart-title', 10);
$message = __('Cart', 'woocommerce');
echo '<span class="cart-title">' . $message . '</span>';
}, 9);
How can I change the cart-title to just Cart?
You can use this to change cart page title
function wpa_change_my_basket_text( $translated_text, $text, $domain ){
if($translated_text == 'Cart:' )
$translated_text = 'Basket:';
return $translated_text;
}
add_filter( 'gettext', 'wpa_change_my_basket_text', 10, 3 );
I've been trying to change my layout for the empty-cart message. I've removed the action, and try to replace it.
I'd like to change the htm structure output from:
<p class="empty-cart"></p>
to:
<div class="col-12 offset-md-1 col-md-10"><p class="empty-cart"></p></div>
My actual code (in functions.php file of my theme):
/** Change the output for empty-cart within a div */
remove_action( 'wc_empty_cart_message', 'wc_empty_cart_message', 10 );
add_action( 'wc_empty_cart_message', 'wc_empty_cart_message', 10 );
function custom_wc_empty_cart_message() {
echo '<div class="col-12 offset-md-1 col-md-10"><p class="cart-empty">'
. wp_kses_post( apply_filters( 'wc_empty_cart_message', __( 'Your cart is currently empty.', 'woocommerce' ) ) ) . '</p></div>';
}
But this code doesn't work. Does anyone has a suggestions on how to make this work?
Here below is the correct way to make it work:
remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );
add_action( 'woocommerce_cart_is_empty', 'custom_empty_cart_message', 10 );
function custom_empty_cart_message() {
$html = '<div class="col-12 offset-md-1 col-md-10"><p class="cart-empty">';
$html .= wp_kses_post( apply_filters( 'wc_empty_cart_message', __( 'Your cart is currently empty.', 'woocommerce' ) ) );
echo $html . '</p></div>';
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
To remove empty cart message use just:
remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );
I am overriding the admin email notification template in WooCommerce and when the order transaction is successful I want to add the transaction id in the email.
I tried $order->get_transaction_id() as explained here in the admin email template, but it returns an empty result.
I then tried this in the admin email template:
do_action('getOrderTransactionID', $order->id);
And in my theme's functions.php I added this but this function doesn't return anything either.
add_action('getOrderTransactionID', 'getOrderTransactionIDForEmail');
function getOrderTransactionIDForEmail($orderId){
echo get_metadata('post', $orderId, '_transaction_id', true);
//get_post_data doesn't return anything either
//get_post_meta( $orderId, '_transaction_id', true);
}
In the wp_postmeta table, the _transaction_id meta key is saved after each successful transaction. Why then am I unable to retrieve the _transaction_id which is already in the database?
What gateway are you using? If you don't see _transaction_id then you need to save the returned transaction_id manually in your gateway plugin. Check out this page
Try saving transaction id in your payment gateway file, then try to see if it displays when you do var_dump(get_post_custom($order->id));
add_post_meta( $order->id, '_transaction_id', YOUR_TRANSACTION_ID, true );
The following is an example of how to add data to email templates using existing hooks.
function kia_display_email_order_meta( $order, $sent_to_admin, $plain_text ) {
$some_field = get_post_meta( $order->id, '_some_field', true ),
$another_field = get_post_meta( $order->id, '_another_field', true ),
if( $plain_text ){
echo 'The value for some field is ' . $some_field . ' while the value of another field is ' . $another_field;
} else {
echo '<p>The value for <strong>some field</strong> is ' . $some_field. ' while the value of <strong>another field</strong> is ' . $another_field;</p>;
}
}
add_action( 'woocommerce_email_order_meta', 'kia_display_email_order_meta', 30, 3 );