I'm using Woocommerce Subscriptions and currently the below action hook fires when you update your address on your Account Page > Edit Shipping (my-account/edit-address/shipping/) - HOWEVER it does not fire when you update your address on the Account > View subscription page > Edit Shipping (/my-account/edit-address/shipping/?subscription=62400).
function kidstir_email_customer_address( $user_id ) {
// do stuff
}
add_action( 'woocommerce_customer_save_address','kidstir_email_customer_address', 20 );
I've been looking for hours, and can't figure out why it's not firing, or how to get a notification that a subscription address has changed. Has anyone else had this issue?
The version of WooCommerce Subscriptions (2.0.9) does not call the woocommerce_customer_save_address hook in file class-wc-subscriptions-addresses.php
To solve my problem I edited this file (I know editing core is not advisable) to call the hook (doaction etc) on line 137.
According to official documentation of the WooCommerce Subscriptions plugin, there is a updated_users_subscriptions hook.
Related
I use this plugin: https://wordpress.org/plugins/aramex-shipping-woocommerce/
But I try any means but I failed to solve the issue . I have active Aramex account with all details, I setup plugin in woocommerce settings, but after click view cart show Aramex: ERR52 - Destination my city and address are invalid while I start shop as a guest. Also is it possible to disable ZIP code while use Aramex? Please any one with idea what cause this
the zipcode requirements are based on each country , for eg: GCC countries do not need zip code and most other countries need zipcode.
You can have WooCommerce override the default setting that makes the field required by adding a filter to your theme's functions.php. It would be best practice is to create a child theme so it won't get overwritten each time you update the theme.
For example, this code will remove the "required" state from the billing and shipping postal codes during checkout (if the shipping country is not 'US'):
add_filter( 'woocommerce_checkout_fields','custom_override_default_address_fields' );
function custom_override_default_address_fields($fields){
global $woocommerce;
$country = $woocommerce->customer->get_shipping_country();
if($country !== 'US'){
$fields['billing']['billing_postcode']['required'] = false;
$fields['shipping']['shipping_postcode']['required'] = false;
}
return $fields;
}
For more details on filters and fields available to edit via filtering see WooCommerce Customizing checkout fields using actions and filters doc
I've got a problem
Once I go to the checkout page after having added one item or more to my cart, it shows the billing checkout form with already filled inputs. See below:
It shows my full details, including email and phone number to every possible buyer.
I installed the SendGrid plugin and discovered it, but removing the plugin did not fix the issue.
I cannot see in any WordPress option where I can edit the value of these input boxes to be empty.
Super weird...
one thing you can try, is using a hook to alter the current "default" value of your form
Since I don't know, in what priority the default value is already getting changed, I would start by setting it to 20, and then trying 30, 40 etc.
// Hook in -
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields', 20 );
// Our hooked in function - $address_fields is passed via the filter!
function custom_override_default_address_fields( $address_fields ) {
$address_fields['first_name']['placeholder'] = 'Firstname';
return $address_fields;
}
Hope this works - It was way to long for a comment.
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
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.
I am setting up an ecommerce site using Wordpress and WooCommerce. We are using the wordpress member accounts to track customer information, and we need a way for logged in members only to be able to choose to purchase their cart "on credit", meaning no payment is required to place the order. Basically what I have done is hi-jacked the "Check" option (since we don't need it anywhere else) and renamed it "Credit" since it allows for the functionality we need.
However, I need a way for the "Credit" (check) option to only display if the user is logged in. Is there any way I can just "unhook" this option if the user isn't logged in? This seems like something that would be easy to do, but I couldn't find anything about it. Any help is appreciated.
The original answer to this question (from BWDesign) no longer works due to changes in WooCommerce (at least from WooCommerce 2.1.7 onwards, possibly before). This does the trick now (tested on 2.1.7 and 2.1.8), add it to e.g. your functions.php file:
add_filter( "woocommerce_available_payment_gateways", "rp_filter_gateways", 9999 );
function rp_filter_gateways($args) {
if(!is_user_logged_in() && isset($args['cheque'])) {
unset($args['cheque']);
}
return $args;
}
I just found the solution. In the class-wc-cheque.php file, the check or "cheque" (crazy brits) option is hooked using add_filter('woocommerce_payment_gateways', 'add_cheque_gateway' );. So the solution was simply to add this code to my functions.php file:
if(!is_user_logged_in()){
remove_filter('woocommerce_payment_gateways', 'add_cheque_gateway' );
}
Hope this helps!