We get constant fake orders from our competition, we need to see the real city behind the IP the client placed the order, so we would like to see some field called ‘real city’ on the email that we received on each order. Until now we managed to get the IP by adding this line on function.php but its time consuming to open browser and manually search the city to see if match the client order city. As you may notice we added the real city line but its only extracting what the client selects so its not good, could I get the city name based on IP ? Thank you !
function send_customer_city( $order, $sent_to_admin, $plain_text, $email ){
if( ‘new_order’ == $email->id ){
echo ‘<br>
<p>‘.__(‘Client IP’).’: ‘. get_post_meta( $order->id, ‘_customer_ip_address’, true ).'</p>
<p>‘.__(‘Real City’).’: ‘. get_post_meta( $order->get_id(), ‘_billing_city’, true ).'</p>’;
}
}
In place of doing this You can do one thing
You can place a hidden filed on the checkout form and set the city according to IP/LAT-LONG
using any API. using woocommerce hooks woocommerce_after_checkout_billing_form
AT the time of placing an order You can get this filed data as well to check that Is This Real order Or fake?
OR
You can also check this before placing an order to avoid fake orders creations using woocommerce_review_order_before_submit or any other hook
Related
My customer wants to enable for some specific customers to pay afterwards via invoice.
So i've added an extra field in the user profiles, where he can select yes/no.
This field works fine and saves properly.
Depending on the choice:
no = default webshop behavior and customer needs to pay direct.
yes = customer can order items without paying, he'll get an invoice later on.
Also tried different payment methods, but they are available for everybody, i only want them for specific users.
Now i've tried based on that field in the functions.php to add a conditional filter like so:
if (esc_attr( get_the_author_meta( 'directbetalen', $user->ID ) ) == 'no') {
add_filter('woocommerce_cart_needs_payment', '__return_false');
}
But it doesn't seem to work?
I want payment to be skipped when the field is set to no.
Else proceed as normal and customer needs to pay.
Using WordPress get_user_meta() function, try the following :
add_filter( 'woocommerce_cart_needs_payment', 'disable_payment_for_specific_users' );
function show_specific_payment_method_for_specific_users( $needs_payment ) {
if ( get_user_meta( get_current_user_id(), 'directbetalen', true ) === 'no' ) {
$needs_payment = false;
}
return $needs_payment;
}
Code goes in functions.php file of your active child theme (or active theme). It should work.
Let me start by saying that I have no code yet, and have researched this without finding anything. If anyone could point me in the right direction, it would be great.
Basically, I want to preferably use a code functions.php that checks the payment method of a WooCommerce order and sends the standard new order email to a specific email address. This address could be hardcoded to make it more simple.
What I want to achieve is that every time an order is placed with Stripe as the payment method, the standard new order email is sent to this additional email address while also being sent to the specified address in the WoocCommerce settings. If any other payment method is used, nothing should happen besides the normal new order email getting sent.
I would be very thankful if anyone could point me in the right direction, but please keep in mind that I am not a super-coder by any means.
Try the following code that will add an additional recipient to "New Order" email for stripe payment gateway:
add_filter( 'woocommerce_email_recipient_new_order', 'new_order_additional_recipients', 20, 2 );
function new_order_additional_recipients( $recipient, $order ) {
if ( ! is_a( $order, 'WC_Order' ) )
return $recipient;
// Set Below your additional email adresses in the arrayy
$emails = array('name1#domain.com');
$emails = implode(',', $emails);
// Adding recipients conditionally
if ( 'stripe' == $order->get_payment_method() )
$recipient .= ',' . $emails;
return $recipient;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
My issue: The client has 12 locations, each location is a different corporation hence a different PayPal account per business. By default woocommerce only supports one email to be entered to process the payment. The goal is to use one installation of wordpress / woocommerce then direct the user to the PayPal account associated with the location they have selected upon checkout.
My Theory / Attempt: originally I thought of implementing this feature by setting up a variation so the user can select a location which will then pass a parameter to the URL. The parameter would later be used within the PHP to overwrite the default email.
My Problem: I am having trouble with overwriting the default email that is entered within the admin settings, I cant seem to locate this email in the database. I am assuming the file pertaining this modification is located at: wp-content/plugins/woocommerce/includes/gateways/paypal but would prefer doing this the wordpress way vs editing core files, for obvious reasons. After doing some research I have found the following action shown below, but this is for the proceed to checkout button, I am looking to interact with the proceed to PayPal button. I am fluent in PHP but not the best with WordPress development. I would think this is a popular issue since majority of franchises would deal with such a scenario, but I am unpleasantly surprised on the amount of information regarding this topic. If someone could point me in the right direction of conquering this task it would be greatly appreciated!
remove_action('woocommerce_proceed_to_checkout','woocommerce_button_proceed_to_checkout', 20);
add_action('woocommerce_proceed_to_checkout', 'change_url_to_checkout', 20);
function change_url_to_checkout(){
$extra_url = 'put_your_extra_page_url_here';
?>
<?php _e( 'Proceed to Checkout', 'woocommerce' ); ?>
<?php
}
I can see two functions to be written here.
1. To alter the order data when an order is created. This is where we save the email needed.
add_action( 'woocommerce_checkout_update_order_meta', 'woocommerce_checkout_update_order_meta' );
function woocommerce_checkout_update_order_meta( $order_id ) {
$email = 'paypal#location1.com';
// do something here as to use the right email.
// you have $order_id.
// can be used as:
// $order = wc_get_order( $order_id );
// $order->get_billing_address_1() to get the address to check order address.
// or use $_POST['location'] if ever you posted some data.
update_post_meta( $order_id, '_alternative_paypal_email', $email );
}
2. Then use woocommerce_paypal_args to alter the args that is being passed to paypal.
add_filter( 'woocommerce_paypal_args', 'woocommerce_paypal_args', 10, 2 );
function woocommerce_paypal_args( $paypal_args, $order ) {
$email = get_post_meta( $order->get_id(), '_alternative_paypal_email', true );
if ( !empty( $email ) ) {
$paypal_args['business'] = $email;
}
return $paypal_args;
}
To summarize, this is just an example. But these two hooks is enough to get what you need.
I am trying to get my customer's shipping address during checkout. What we are trying to do is make it so that if they attempt to ship by UPS to a PO Box, it outputs an error page. In the checkout page, there is a checkbox where they can check the different addresses that are saved into their account. I've gotten it where it correctly detects whether or not they are using UPS, however I can't get it to properly get the customer's address. No matter what I do, it records the default shipping address, even if they select another one. My question is what can I do to make it where it selects address 2 instead of address one? Here is my code. The reason the error outputs $street is so I can see what is contained in the variable $street.
$quote = $this->getOnepage()->getQuote();
$shippingAddress = $quote->getShippingAddress();
$street = $shippingAddress->getStreet1();
//Check to see if customer is trying to use UPS to ship to a PO Box.
if (preg_match("/p\.* *o\.* *box/i", $street)){
if ((($shippingMethod=="tablerate3_bestway") || ($shippingMethod=="tablerate_bestway") || ($shippingMethod=="tablerate2_bestway"))){
$result = array (
'error' => -1,
'message' => $this->__($street)
);
$this->getResponse()->setBody(Zend_Json::encode($result));
}
}
For shipping address
Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getData();
For Billing Address
Mage::getSingleton('checkout/session')->getQuote()->getBillingAddress()->getData();
I am trying to customize the "Order Complete" email. Specifically, I have some products (software) that require license keys. So far, I've finished my algorithm for generating and storing the license keys (as well as verification) in a database.
In my child theme, under /woocommerce/order/order-details.php, I've added the corresponding code to add the license keys to the database. I don't want to display them on the order-details page, because the user could close this webpage and then lose the keys. So, I want to send them in an email (or display the keys in both the email and the order-details page). I want to use the "Order-Completed" email, because I don't want to send multiple emails.
I figured out how to add on to the order-details.php template because there was the pre-existing WC_ORDER instance: $order = new WC_Order( $order_id ). After that, I just looked through the documentation to find the correct methods that I needed, and I came up with this:
foreach( $order->get_items() as $item ) {
$_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
$item_meta = new WC_Order_Item_Meta( $item['item_meta'] );
?>
// some code that was already included
if ( $_product && $_product->exists() && $_product->is_downloadable() && $order->is_download_permitted() ) {
if ($_product->get_attribute('needs_license_key') == "True") { // custom attribute for my software
// generate and store license keys
I only had to add in the if ($_product->get_attribute('needs_license_key')... part, so it was not very complex.
However, this is not present in the Order-Completed template, so I'm not sure where this goes. I'd need to iterate through all the products, check if they are downloadable (I have the code for that already), and then locate the product keys (I know how to do that as well). My main question is: How do I find out what order number the email is being sent for, as well as other stats for that order (such as products listed and their attributes, so I can iterate over them as seen above)? I'm not sure how to do this exactly with WooCommerce.