woocommerce billing address form always appear even if the user is logged in? - wordpress

I'm looking for a way to disappear woocommerce billing address in checkout page when the user is logged in. Is that possible? And in first place, Why is that?! Why billing address form is always showing in checkout page even when the user is logged in?!!!

1) For your question one try this:
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
if( is_user_logged_in() ){
unset($fields['billing']);
$fields['billing'] = array();
}
return $fields;
}
2) For your question two :
If user wants to modify something in billing form, this is the place where he can modify nothing else. If you think this is not correct, better to develop a plugin, maybe a lot of people will be thinking this.

Related

Unlogged user cannot see store and must go to login and successfully logged in users must be redirected to store

I am working on a Wordpress site with Woocommerce. I am using this function inside functions.php to redirect everyone who visits my store to login since it is a private area. Once the person logs in, they should be redirected to the store again. I have the following code implemented, which works for me to get all those trying to navigate my store to log in, I need to modify this code so that once logged in, it redirects me to the store page in woocommerce, in my case the page of the store is called "tienda".
To clarify: Users who are not registered or logged in, should not be able to see the store or cart or anything from woocommerce, I already implemented this with a wp-members plugin, if they try to navigate these woocommerce urls, they must go to login. When you have already logged in, you should go to the store, in my case you should not redirect to the previous link, but must inevitably go to the page called "tienda".
On the other hand, I would like to know if my function is missing something or is well built. Thank you!
function loggedoutuser_redirect() {
if (
! is_user_logged_in()
&& (is_woocommerce() || is_cart() || is_checkout())
) {
header('Location: ' . wp_login_url());
exit;
}
}
add_action('template_redirect', 'loggedoutuser_redirect');
function woocommerce_login_redirect_custom( $redirect, $user ) {
$redirect = wc_get_page_permalink( 'shop' );
return $redirect;
}
add_filter( 'woocommerce_login_redirect', 'woocommerce_login_redirect_custom', 10, 2 );
Paste this above snippet at the end of your active child theme functions.php file or else if you are good in plugin development then create a custom plugin.
Snippet Explanation:
Create a custom function to redirect after logged in
Fetch the shop URL using WooCommerce helper function wc_get_page_permalink( 'shop' ) and assign it to the variable $redirect
Then return the URL
Hook the custom function to the filter hook woocommerce_login_redirect
Note: You can check the user role inside our custom function then based on the role you can redirect it to the dashboard if he is administrator else to the shop page.

Backorder Notification Woocommerce

I have a little problem with the backorder notification on my woocommerce shop.
What it is now: I set in the product backorders: allowed, but notify customer. When I press a variaton on the product page it will show available for backorder. So far so good. When someone place the order it will show the text backorderer: 1 on the order confirmation, on the pdf invoice, on the e-mail.
What I want: Show the notification only on the product information page. Not on the e-mails, order confirmation, etc. But when I set up backorders only to allow. There is also no notification on the Product Page for the customer.
So do someone of you know, how I can change this? Is there a custom code or something else I can use.
This is really important for me. I tried to find a solution about 1 week without any luck. So please help me.
Can you try this?
Just copy and paste this block of code to your functions.php file in your child theme.
add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2); function wcs_custom_get_availability( $availability, $_product ) { // Change In Stock Text if ( $_product->is_in_stock() && ! $_product->backorders_allowed() ) { $availability['availability'] .= __('<br />Shipped immediately', 'custom'); } if ( $_product->is_in_stock() && $_product->backorders_allowed() ) { $availability['availability'] = __('<br />We will inform you via email when the product is back in stock. Please send us your contact info via the form below.', 'custom'); } // Change Out of Stock Text if ( ! $_product->is_in_stock() ) { $availability['availability'] .= __('<br />We will inform you via email when the product is back in stock. Please send us your contact info via the form below.', 'custom'); } return $availability; }
And let me know whether it worked for you or not.
Thank you

Woocommerce woocommerce_order_status_processing trigger only in user side

Hi I would like to ask you guys if this is possible in Woocommerce hooks
the hook I'm using is this one,
woocommerce_order_status_processing
I want this hook only to be called in user side after payment, which is works ok but in the admin if I change the oder status, this hook is also triggering, can I disabled my custom hook in admin and will run/trigger only for the user side?
add_action( 'woocommerce_order_status_processing', 'order_extracode' );
function order_extracod( $order_id) {
.....
}
the above code is the function and hook I added, I tried !is_admin() but it is not working, and still processing this function in Admin Orders
thanks (TIA)
This hook will be executed every time there's a statu change.
What you can do is to decide if you want to execute the code in the front or in the Dashboard.
add_action( 'woocommerce_order_status_processing', 'order_extracode' );
function order_extracod( $order_id) {
if( ! is_admin()){
// Your code here
}
}
The only conditional tag to detect if you are in the dashboard or not is the is_admin()
WooCommere cannot tell the difference between who is triggering the woocommerce_order_status_processing action.
If you want something to happen when the user completes payment, you could try the woocommerce_payment_complete hook in abstract-wc-order.php.
Alternatively you can use current_user_can() function to determine the whether the hook can be executed or not, like this
if( !current_user_can( 'administrator' ) && !current_user_can( 'manage_options' ) ) {
//do your stuff
}

How to prevent user deletion from WordPress dashboard

The question is simple. I need to make it impossible to delete a user account in the WordPress backend for every other user. Is there any function I can add to functions.php to achieve this?
The delete_user action hook fires immediately before a user is deleted from the database. Use priority 0 and cross your fingers you're the only one hooking on that priority :)
add_action( 'delete_user', 'so27135610_delete_user', 0, 2 );
function so27135610_delete_user( $id, $reassign )
{
die( "You're not allowed to delete users on this site." );
}

how to prevent woocommerce saving user untill they pay?

I am using woocommerce subscription. It is saving user and makes them logged on once they finish checkout form. How to make like they do not get saved / logged-in until payment success?
You could hook into the woocommerce_thankyou hook and logout the current user there. But that is a little late. Better would be the user to be logget out before the page is displayed, not after.
add_action( 'woocommerce_thankyou', 'my_custom_logout_function_here', 10 );
function my_custom_logout_function_here( $orderid ) {
echo 'Your message here';
wp_logout();
}

Resources