Display a custom message for cheque payment method in WooCommerce thankyou - php

I am trying to modify the page thanks to buy at WooCommerce, at least for the method of payment by bank check.
All I want to do is show a summary of the order and empty the cart, because currently shows me an empty page with the text that the cart has been emptied. Is there a hook that allows me to insert code on the page thanks for paying by bank check?
I found the 'woocommerce_thankyou' action but I do not know what to do with it, does anyone explain to me a little?

you can target cheque payment method using woocommerce_thankyou_cheque action hook, that will display a custom message on order received page for cheque payments:
add_action( 'woocommerce_thankyou_cheque', 'woocommerce_thankyou_cheque_payment', 10, 1 );
function woocommerce_thankyou_cheque_payment( $order_id ){
if( ! $order_id ) return;
// SET your message below
echo '<p>'.__( 'Thanks for paying by cheque message.', 'woocommerce' ).'</p>';
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works.

Related

Move cart.php and cart-totals.php to checkout page

To reduce the number of redirects on my site, i added the cart page on the same page as the checkout. and used this code to do it:
function cart_on_checkout_page_only() {
if ( is_wc_endpoint_url( 'order-received' ) ) return;
// add woocomerce cart shortcode on checkout page
echo do_shortcode('[woocommerce_cart]');
}
// Cart and Checkout same page
add_action( 'woocommerce_before_checkout_form', 'cart_on_checkout_page_only', 5 );
The problem is in the layout specifically, on devices it is too far from the order items as the order total is at the bottom of the page near the checkout button. I got a lot of complaints because people are too lazy to scroll down to see the coupon application in the cart at the bottom of the page
so I made the following modification:
I copied the woocommerce plugin files woocommerce/template/cart/cat.php and cart-totals.php
and pasted it into my theme in themes/mytheme/template/cart/custom-cart.php
and adapted it in the code above:
function cart_on_checkout_page_only() {
if ( is_wc_endpoint_url( 'order-received' ) ) return;
// add custom cart template on checkout page
get_template_part('template/cart/custom-cart');
}
// Cart and Checkout same page
add_action( 'woocommerce_before_checkout_form', 'cart_on_checkout_page_only', 5 );
my code did the job, but I believe there should be a simpler and more elegant way to make this kind of change. it's possible to make more simpler?
by the way I'm using a child storefront theme.

Add WC_Payment_Gateway description to Woocommerce option payment with Skrill plugin

I'm using the skrill plugin for electronic payments. the plugin plugin, however, does not give me the possibility to add a description to the payment method, how can I do it using the function file? I tried to use the code on this page:
Additional field on checkout for specific payment gateway in Woocommerce
but it does not work, how can I do?
The hook woocommerce_gateway_description can't work for SKRILL payment options as WC_Payment_Gateway get_description() is not defined in SKRILL plugin code.
So you shuld need to tweak it differently to have a description for SKRILL payment options in Woocommerce checkout page, this way:
add_filter( 'woocommerce_gateway_icon', 'gateway_skrill_description', 10, 2 );
function gateway_skrill_description( $icon, $payment_id ){
if ( \strpos($payment_id, 'skrill') !== false ) {
$description_text = __("You can pay with your credit card if you don’t have a SKRILL account...", "woocommerce");
$icon .= '</label><div class="payment_box payment_method_'.$payment_id.'" style="display:none;"><p>'.$description_text.'</p></div>';
}
return $icon;
}
Code goes in function.php file of your active child theme (or active theme). tested and works.

Customizing totals lines in Woocommerce customer email notifications

My woocommerce sends out an as it is suppose to.
How ever the tax fields shows up with what seems to be an unclosed tag.
I have grepped thru the entire woocommerce code, but I cant find where the tags are generated.
this is how my tax field looks in the email.
Total: DKK 0.00 <small class="includes_tax"
This can only be the result of a customization that you have made on order totals, or that your theme or a plugin is making. By default there is no such behavior in Woocommerce. It seems in your case due to a plugin (or some customizations) that displays the currency symbol as a Code.
Now order totals rows in Woocommerce email notifications are generated using the WC_Order method get_order_item_totals()
Then you can make changes in it using the following code:
add_filter( 'woocommerce_get_order_item_totals', 'customize_order_line_totals', 1000, 3 );
function customize_order_line_totals( $total_rows, $order, $tax_display ){
// Only on emails notifications
if( ! is_wc_endpoint_url() || ! is_admin() ) {
// Remove any other html tags from gran total value
$total_rows['order_total']['value'] = strip_tags( wc_price( $order->get_total() ) );
}
return $total_rows;
}
Code goes in function.php file of your active child theme (or active theme). It should solve your problem.
But the best way should be to find out the guilty, instead of patching something wrong done by some customization somewhere.

WooCommerce Empty cart after payment with custom gateway API

I'm working on custom API for Merchant Safe Unipay (MSU) for woocommerce and need to change quantity after successful payment.
Here is process:
Customer collect articles in shopping bag
When click on "Pay All" it is redirected to MSU where need to fill Credit Card info
After payment, MSU return him back to website where PHP send emails and print message about payment.
All works well but can't find hook where and how to mark all products from shopping card payed and change quantity.
How can I do that?
Thanks
Normally after payment process, the customer is redirected to "Thank you" page (or "Order received" where customer can review his payed order)… Normally the cart is emptied somewhere (I don't remember where exactly).
So if not emptied, you need to do it for example with (2 different hooks options):
add_action( 'woocommerce_checkout_order_processed', 'order_received_empty_cart_action', 10, 1 );
// or
// add_action( 'woocommerce_thankyou', 'order_received_empty_cart_action', 10, 1 );
function order_received_empty_cart_action( $order_id ){
WC()->cart->empty_cart();
}
The Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
You will have to test that, to see if it's convenient…
With this code the payment is skipped. (Versión WC 3.5.7).
I include the code of class-wc-checkout.php lines 983 - 989:
do_action( 'woocommerce_checkout_order_processed', $order_id, $posted_data, $order );
if ( WC()->cart->needs_payment() ) {
$this->process_order_payment( $order_id, $posted_data['payment_method'] );
} else {
$this->process_order_without_payment( $order_id );
}
If we clean the cart, it takes the else route:
$this->process_order_without_payment( $order_id );

WooCommerce - Skip cart page redirecting to checkout page

Our website is kohsamuitour.net. I have added custom code to skip the cart page on checkout, which works for all sales. This code:
function wc_empty_cart_redirect_url() {
return 'https://www.kohsamuitour.net/all-tours/';
}
add_filter( 'woocommerce_return_to_shop_redirect', 'wc_empty_cart_redirect_url' );
Now that does the job, but we also have a possibility to check booking availability. That can be found on the pages of private charters, i.e. this one: https://www.kohsamuitour.net/tours/kia-ora-catamaran/ .
Here the customer is being redirected to the cart, where I don't want that to happen as this is not a sale.
How can I make sure the 'Check booking availability' is also redirected to the checkout straight away?
You can skip cart definitively, redirecting customers to checkout page when cart url is called.
To achieve this use this code snippet, that should do the trick:
// Function that skip cart redirecting to checkout
function skip_cart_page_redirection_to_checkout() {
// If is cart page, redirect checkout.
if( is_cart() )
wp_redirect( WC()->cart->get_checkout_url() );
}
add_action('template_redirect', 'skip_cart_page_redirection_to_checkout');
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
The code is tested and fully functional.
Edit: Since WooCommerce 3 replace wp_redirect( WC()->cart->get_checkout_url() ); by:
wp_redirect( wc_get_checkout_url() );

Categories