I tried to update user meta field after the checkout payment is successful. I tried keeping the following code in thankyou.php
update_user_meta($user->ID, '_uw_balance', $updated_balance);
Actually i'm using a wallet plugin called "User Wallet Credit System" and using the user wallet balance to get deducted in the total order amount. I'm able to deduct the wallet amount in order total but unable to update the wallet after the successful payment.
I'm using woocommerce for the checkout and everything. I need to how should i update the wallet amount after the transaction is processed.
Use woocommerce_thankyou being called after successful checkout.
you can play with order id,
add_action('woocommerce_thankyou', 'update_e_wallet', 11, 1);
function update_e_wallet($order_id) {
//do something...
}
also you can get user by order id
$order = new WC_Order( $order_id );
$user_id = $order->user_id;
Related
I'm faced with a little problem.
I need to send the Customer Invoice / Order Details email automatically when an order is completed.
I haven't found any action or filter to apply in this case an the internet is not useful. Has anyone an idea how to send this email when the order status switches?
Best regards!
You can use woocommerce_order_status_completed hook and WC_Email_Customer_Invoice
add_action( 'woocommerce_order_status_completed', 'mysite_woocommerce_order_status_completed', 10, 1);
function mysite_woocommerce_order_status_completed( $order_id ) {
// Send invoice email to customer
//use order ID as trigger value
WC()->mailer()->emails['WC_Email_Customer_Invoice']->trigger($order_id);
}
I'm developing a plugin that needs to get the order ID on the final checkout page when a customer purchased a product. How do I do that?
I tried
global $order
var_dump($order);
And all I see is "DESC". I need to access the current order of the customer who is looking at the page.
I need to get the order id in the frontend and add that ID to a script, also on the front end, so that when a client orders a product and pays, the page will load, show them the "Thank you, here is your order number: xxx". At that moment I need my script to, for example, execute a console.log("The oder ID is:", order_id);
To get the order ID on the final checkout page when a customer purchased a product you can use the woocommerce_thankyou hook, where the callback function already contains the order ID.
// define the woocommerce_thankyou callback
function action_woocommerce_thankyou( $order_id ) {
echo "Thank you, here is your order ID: " . $order_id;
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
// Customer billing country
$billing_country = $order->get_billing_country();
// etc..
};
// add the action
add_action( 'woocommerce_thankyou', 'action_woocommerce_thankyou', 10, 1 );
I use a custom status: Payment Due. Once an order gets the status Payment Due it will automatically trigger a email after 14 days reminding the customer to pay for their order.
Now when this customer tries to pay but it fails for whatever reason the order will get the status Cancelled.
But I need this order to get back to status Payment Due or something similar like Payment Failed.
So for particular statuses I would really like to remove the status Cancelled and Failed from applying when a customer fails to complete the payment and apply a other custom status in stead
The following hook did the trick:
add_action( 'woocommerce_order_status_reminder_to_failed',
'change_status_to_payment_required' , 10, 10 );
function change_status_to_payment_required( $order_id ) {
$order = wc_get_order($order_id);
$order->update_status( 'payment-required' );
}
I'm looking for a solution where we can disable woocommerce sending email notification when an order is done by a client from a specific customer group (user role).
I found answer about a situation what prevent sending email for a specific product-ID.
Disable WooCommerce email notification for specific product.
Maybe this could be possible for our 'problem' too?
Kind regards,
Kees
You can use the hook for any email and inside the callback function you can check if the user has a specific role
function change_new_order_email_recipient( $recipient, $order ) {
global $woocommerce;
$uid = $order->get_user_id();
$user_meta=get_userdata($uid);
$user_roles=$user_meta->roles;
if(in_array('customer', $user_roles)){ // Prevent email if user role is customer
$recipient ='';
}
return $recipient;
}
add_filter('woocommerce_email_recipient_customer_completed_order', 'change_new_order_email_recipient', 1, 2);
I have checked the code rapidly and is working
I'm using woocommerce subscriptions with the custom function like below and can only get the parent order id from $subscription (from the order that initiated the subscription rather than getting each new order ID as renewals get triggered). Does anyone know how to get each new recurring order id?
add_action( 'woocommerce_scheduled_subscription_payment', 'record_parent_referral_on_payment' );
function record_parent_referral_on_payment( $subscription ) {
....