Woocommerce: How to Update Payment Method - woocommerce

I'm on checkout page!
I've created a new payment gateway called "others", the user choose this gateway and a drop-down list with payment options such as "Visa, MasterCard, etc" becomes available.
When the user choose an option e.g.:"VISA", I want that the payment method title becomes "VISA", not "others".
I've try to use:
$order->set_payment_method_title($_POST[$this->id.'-admin-note']);
But it doesn't work. Can someone help me? Does someone know how to change the payment method title?

Hello this was the solution i found.
update_post_meta( $order_id, '_payment_method_title', 'Pay' );

Related

Display a "USER" ACF Field on Woocommerce Orders Detail Page

I hope someone can kindly help with our Woocommerce problem.
I've been stuck looking for examples on how to display an ACF (Advanced Customs Field) field on the Orders Details Page. The difference with my query to others is that the ACF field is set against user information. So in the ACF Field group, I have set "User Role" "is equal" to "All". This works fine and the field can be seen when viewing USERS in the backend. Via the ACF plugin, it will save data against the user.
The field label is "Credit Account Status", and field name is "credit_account_status". Its a checkbox field with 3 options:
Active - No credit given
Active - Credit OK
ON STOP - credit removed; see Accounts Dept.
We want to call up this field when viewing orders on the Order Details page - maybe underneath the shipping address section at the top of the order page. We want this as a visual to prevent us raising new orders manually for someone who hasnt paid their bills on time!
Can anyone help please?
I previously tried to edit the below code, but my programming is very poor - this code seems to bring in data from Order meta, not USER meta.
/**
Display field value on the admin order edit page..
PHP Custom Feild Value
*/
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo ''.__('Store Location').': ' . get_post_meta( $order->id, 'My Field', true ) . '';
}
Best wishes, Craig

Hide Place Order button when no shipping options are available

My woocommerce shop is UK based, selling bulky items to both the UK market and internationally using FedEx.
I use FedEx for international shipping but sometimes an address cannot be shipped to and the customer gets the 'no shipping available' message. However, as far as I can tell, Woocommerce STILL allows the customer to place the order in these situations resulting in an order that cannot be fulfilled. Is there a simple setting somewhere that I am missing that says if no shipping is available, don't let the order be placed?
I did find this resource - https://www.bolderelements.net/support/knowledgebase/removing-checkout-button-shipping-not-available/ but that only removes the ability to get to the checkout page.
It seems like there should be a setting for something this basic?
I ended up solving this by not hiding the button, but by forcing an error if there is no shipping. I'm using the woocommerce_checkout_process action for this:
function is_valid_shipping() {
$selected_shipping = WC()->session->get('chosen_shipping_methods');
if(in_array(false, $selected_shipping)){
wc_add_notice( __( 'Your Shipping is not valid.' ), 'error' );
}
}
add_action( 'woocommerce_checkout_process', 'is_valid_shipping' );
Hope this helps someone else!

Prevent redirect WooCommerce checkout form after complete

Just trying to stop checkout form stay still after checkout form submit complete. As we know WooCommerce checkout form submission done by ajax ?wc-ajax=checkout. As default after successfully complete an order checkout form redirect to thankyou page but that not what I want to do.
I want after successfully complete an order checkout form stay still. I will redirect later after done some my own ajax or coding.
I look WooCommerce checkout.js didn't find any hook or anything to do that, So here I am to ask you guys to know anyone how to do this?
NOTE: My main reason to do this, after order status and payment status before checkout gone to thankyou page but for that I need order id and that's why it need to complete first. hope it make sense.
The woocommerce_payment_complete hook is fired when the payment is completed. The only variable passed is the order id, though from that you can get the order object, and ultimately the user.
add_action( 'woocommerce_payment_complete', 'so_payment_complete' );
function so_payment_complete( $order_id ){
$order = wc_get_order( $order_id );
$order->update_status( 'pending' );
$user = $order->get_user();
if( $user ){
// do something with the user
}
}

Woocommerce: on archive page after on_click add to cart show custom data via ajax

So basically, what i want, to show product added in cart also on archive page. I did this functionality, you can refer with image (1 item- already in cart) but my code work on refresh the page. I want to show the same with ajax. As soon as "add to cart" clicked, the data added in mini cart, at same time data will show on product listing page. enter image description here
Go to
Woocommerce > Settings > Products > Enable AJAX add to cart buttons on archives
add_filter( 'wc_add_to_cart_message', 'custom_add_to_cart_message' );
function custom_add_to_cart_message() {
global $woocommerce;
$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') );
return $message;
}
If you want to add your product with quantity using Ajax then definitely WooCommerce default checkbox Enable AJAX to add to cart buttons on archives not works for quantity purpose.
There are many solutions to add this feature. I have implemented it earlier. You just need to add some classes, functions, and script to achieve this.
This is the link which is really helpful for me and you can go through it or you can also check this one. It's not complicated.
If you want to add this in your headers like a mini cart or something. So for that, this one is the best solution for you.
Hope this will helpful for you. Thanks.

Notify email when someone's posted a review in WooCommerce

I noticed that Woocommerce's reviews are managed through Wordpress Comments. But why is it that Wordpress isn't notifying my email when someone posted a review to a product. I have set the "Email me whenever anyone posted a comment".
Is this function available in Woocommerce or i'm missing something?
Please advise, thanks everyone!
Regards, Ven
By default Wordpress sends a notification to the author of the product/post (the person who created the product in your instance). The suggested site owner (settings > general) is not the recipient of these notifications. This is where the trouble might start. This author information is in Woocommerce hidden and is hard to figure out who that is in your user database. It might be that the original author of the product doesn't exist anymore, and especially if the original author has been deleted from the database and you didn't move the contents of that user to a new user.
The default comment notifications are produced in this Wordpress file: wp-includes/pluggable.php
Below is a trick to override the recipient for the comment/review notification, put this code in your child-theme's functions.php and change the part example#example.com to your desired email recipient and you will receive a notification every time someone adds a comment/review to your site.
function new_comment_moderation_recipients( $emails, $comment_id ) {
return array( 'example#example.com' );
}
add_filter( 'comment_moderation_recipients', 'new_comment_moderation_recipients', 24, 2 );
add_filter( 'comment_notification_recipients', 'new_comment_moderation_recipients', 24, 2 );
I tested it and it works.
On the Wordpress Dashboard navigate to Settings > General and the Email address listed here is where you will get notifications.

Resources