Remove payment details Woocommerce order's page in backend - css

I see a post about to translate or change the text "Paid on" on woocommerce backend order's detail page. I integrated it for bacs and local pickup payment.
Replace a specific word for BACS payment method in Woocommerce order edit pages
What I need to add if I want not display the "Paid on" message also when shop manager before set the status to processing (so payment details appears) and then turn back to "wait for payment" or a previous status?
Image attached: Order status is Deleted but it always show the payment details from Completed status set before
Thanks
Update:
Black fields are done because I want to hide real customer informations because I'm sharing the screenshoot here :D
This is to replicate the problem:
Customer makes the order
Order has a initial custom status created from me called "Verifying Stock"
Shop manager make the iter about the stock availability and then set the status to Wait for payment (Bacs or local payment at local pickup)
When shop manager set the status to "Processing", on the header appears the information about payment: "Paid on " and "IP: ..."
If the shop manager set a previous status of "processing", for example "wait for payment", the information "paid on" remains forever, i cannot remove them or update again.
I need to remove details if the order status is different from processing or completed order status.
Thanks

As you shared the screenshot I implemented the logic for you.
You can try this for temporary hide billing, shipping address and IP address
add_action( 'woocommerce_admin_order_data_after_order_details', 'hide_custom_details' );
function hide_custom_details($order) {
$status = array('processing','completed','refunded','cancelled');
$order_status = $order->get_status();
//if(!is_admin() && !in_array($order_status, $status)) {
if(!in_array($order_status, $status)) {
?>
<style>
#order_data .order_data_column:nth-child(2),
#order_data .order_data_column:nth-child(3),
#order_data .woocommerce-order-data__meta.order_number .woocommerce-Order-customerIP{
display: none !important
}
</style>
<?php }
}
If you want to update more, so first Inspect(ctrl+shift+i) and copy class/id as you want to hide and paste inside given CSS.
If you want that, the admin can view every detail then add "!is_admin() &&" inside if the condition like commented if conditions.
you can also update the status accordingly.

Related

How to prevent an admin account with less privileges in WooCommerce to change the stock quantity of a product (prevent decrease and allow increase)

I would like to be able to disable the "decrease button" (but allow the "increase one") in the WooCommerce admin product page.
The reason for this is that I was the person who is responsible for the products to be able to increase the stock quantity in case of new deliveries but NOT able to decrease the stock number for any product.
Do you have any ideas on how to do this?
I'm attaching a photo with the function I want to disable.
I tried to find the method / function but with no success
Those arrows are added by browser because the field is number type, you can't just remove one if them.
You could add some Javascript to trigger when the value of this field is changed and allow only increase, check my code sample.
This is not a really secure solution but I think it covers your requirement.
function disable_stock_decrease_button( ) {
?>
<script>
document.getElementById('_stock').setAttribute('min', document.getElementById('_stock').value);
</script>
<?php
}
add_action( 'woocommerce_product_options_inventory_product_data', 'disable_stock_decrease_button', 10, 0 );
This action is triggered after the quantity field is created and we simply output some javascript code below the field. This javascript will set the 'min' attribute on the stock field to the initial value of that field. The browser will then stop user from decreasing the value to less than initial and if they write it manually, the validation error will be triggered.
This is not very safe solution because one could simply open dev tools and undo the change but I assume you need this to prevent accidental errors. If you need a secure solution, then you have to do the validation on the server side, after the product is saved.

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!

How do I make a specific payment gateway to be free shipping on woocommerce

For those shipping methods, I would like to have:
"Free shipping" only for Cash-on-delivery (COD) payment method (I just renamed it to other label but I am using the COD gateway).
"Flat rate" for other payment gateways (excluding COD payment method of course).
My question: How do I make a specific payment gateway to be free shipping when selected?
For example like in this screenshot:
Similar unanswered question: Woocommerce free shipping based on payment gateway selected
WooCommerce requires that shipping is selected before a gateway, this is how COD works because it checks if an enabled shipping method is selected before providing COD as an option. So if the COD method does not work for you then there is no other way to accomplish this because you are asking the checkout process work backwards from how it was designed.
You can not modify shipping once a payment gateway has been selected due to the way WooCommerce works. You can only add extra fees within the code for each gateway.
After a while of thinking about it, I got curious and thought i'd have a play to see if it was truely impossible. It turns out that with a bit of crude hacking you can actually get this to work, here is a basic plugin that will accomplish the task:
<?php
/**
* Plugin Name: Free Shipping For BACS
* Description: Makes shipping for BACS free.
* Version: 0.0.1
* Author: Kodaloid
* Requires at least: 4.4
* Tested up to: 4.8
*/
if (!defined('ABSPATH')) exit;
add_action('init', 'fg_init');
function fg_init() {
add_action('woocommerce_cart_calculate_fees', 'fg_add_fee');
add_action('wp_footer', 'fg_footer', 9999);
}
function fg_footer() {
?>
<script type="text/javascript">
jQuery(function($) {
setInterval(function() {
$(".input-radio[name='payment_method']").off().change(function() {
console.log('triggered');
jQuery('body').trigger('update_checkout');
});
}, 500);
});
</script>
<?php
}
function fg_add_fee($the_cart) {
global $woocommerce;
if ($woocommerce->session->chosen_payment_method == 'bacs') {
$woocommerce->cart->add_fee('Free Shipping For BACS', -($the_cart->shipping_total), true, 'standard');
}
}
Save the code above as free_shipping_for_bacs.php and install the plugin using the Upload Plugin feature in WordPress.
Basically what this does is check the session to see which payment method has been picked, then if the bacs method is chosen adds a fee which is minus the total of the shipping. This works but because the cart updates using AJAX you need to trigger the update_checkout event attached to the body in JavaScript every time the payment method changes in order to see the change reflected in the cart above.
So as a hack I have added a loop that re-adds the change handler every 500ms to the footer event (if your theme does not implement wp_footer hook, make sure to add it), this can and should be improved upon if you decide to use this code as there are better methods to check if the change event needs re-adding, it's just I don't have a lot of time today.
Koda

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