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.
Related
I created a store by woocommerce and I want redirect customer to payment gateway or reduce wallet after click " add to cart". in other way I want to bypass checkout step.
First, in the admin, go to WooCommerce > Settings > Products and disable both options under Add to Cart Behavior. The two options that you need to disable are:
Redirect to the cart page after successful addition
Enable AJAX add to cart buttons on archives
Next, in your theme's functions.php file, add the following code:
function so55387651_redirect_checkout_add_cart( $url ) {
$url = get_permalink( get_option( 'woocommerce_checkout_page_id' ) );
return $url;
}
add_filter( 'woocommerce_add_to_cart_redirect', 'so55387651_redirect_checkout_add_cart' );
I have a Woocommerce form to 'Add Funds'. It has an amount input field ($20, $30 ...etc.) and a submit button that redirects to cart page with the input amount as total.
Redirect to checkout is working, but the cart items are not getting removed if a user abandons the cart and tries to order again.
I tried numerous solutions for the redirect to checkout, but only one worked.
Working solution for redirect to checkout:
WooCommerce - Skip cart page redirecting to checkout page
Solutions not working for redirect to checkout:
https://wordpress.stackexchange.com/questions/267071/redirect-to-woocommerce-checkout-after-adding-to-cart-item-already-in-cart
Woocommerce add to cart button redirect to checkout
N.B. I have added the working and not working solutions for redirect
to checkout because it may provide an insight as to why the empty cart
solutions are not working.
Incase of emptying cart before adding a new product, none of the solutions are working:
https://gist.github.com/viniciusrtf/b49403b5f87dcd7699c1
https://hungred.com/how-to/empty-woocommerce-cart-adding-item/
https://wordpress.stackexchange.com/questions/267071/redirect-to-woocommerce-checkout-after-adding-to-cart-item-already-in-cart
Using Woocommerce 3.2.6 and WordPress 4.9.2
First you will need in WooCommerce Settings > Products > Display in "Add to cart behaviour" to enabled the checkbox : Redirect to the cart page after successful addition
Then you will need the 3 following hooked function:
1) Empty cart before add-to-cart (if cart is not empty)
add_filter( 'woocommerce_add_to_cart_validation', 'one_cart_item_at_the_time', 10, 3 );
function one_cart_item_at_the_time( $passed, $product_id, $quantity ) {
if( ! WC()->cart->is_empty())
WC()->cart->empty_cart();
return $passed;
}
2) Add-to-cart redirection to checkout:
add_filter( 'woocommerce_add_to_cart_redirect', 'add_to_cart_checkout_redirection', 10, 1 );
function add_to_cart_checkout_redirection( $url ) {
return wc_get_checkout_url();
}
3) Skip cart page redirecting to checkout:
add_action('template_redirect', 'skip_cart_page_redirection_to_checkout');
function skip_cart_page_redirection_to_checkout() {
if( is_cart() )
wp_redirect( wc_get_checkout_url() );
}
Code goes in function.php file of your active child theme (or active theme).
Tested and works (with Woocommerce 3.2.6 and WordPress 4.9.2 on Storefront theme).
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.
I'm using WooCommerce Subscriptions plugin and I would like to stop user role changing only when canceling a subscription.
I found a code snippet here:
add_filter( 'woocommerce_subscriptions_update_users_role', '__return_false', 100 );
… which Stop WooCommerce Subscriptions Changing a User's Role. This will stop role changing when purchasing a subscription too.
What I would like is to stop user role changing only when canceling a subscription.
Is it possible?
Thanks
You could try to use woocommerce_subscription_status_cancelled action hook (without any guaranty as it's untested), this way:
add_action( 'woocommerce_subscription_status_cancelled', 'keep_user_role_unchanged_on_cancelled_status' );
function keep_user_role_unchanged_on_cancelled_status(){
add_filter( 'woocommerce_subscriptions_update_users_role', '__return_false', 100 );
}
The Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Reference: Subscription Status Change Actions
remove_action( 'woocommerce_subscription_status_cancelled', 'wcs_maybe_make_user_inactive_for', 10, 1 );
Use this in your active theme functions.php
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 );