I've created a custom email class and added it to WooCommerce. When I go to the emails setting in WooCommerce I can see my template there and when I trigger it manually the email arrives at the target email account. Now I have the problem that I've added a action to my class which should detect the order status change and do my trigger function if the order gets set to my custom status:
add_action( 'woocommerce_order_status_wc-test-in-progress', array(
$this, 'trigger' ), 10, 10 );
But when I change the order to this status I don't receive any email. Whats wrong here?
https://github.com/woocommerce/woocommerce/blob/master/includes/emails/class-wc-email-customer-on-hold-order.php
You can checkout this file. I've exactly did the same like in this file but replaced all triggers with my custom trigger on order status change.
Wen using woocommerce_order_status_{$status_transition[to]} composite hook, you just need to remove wc- from the status slug like:
add_action( 'woocommerce_order_status_test-in-progress', array( $this, 'trigger' ), 10, 10 );
And it should work.
Related
Problem:
on the checkout page (form-checkout.php) the following action code calls the review order AND the payment method section at the same position (after each other)
do_action('woocommerce_checkout_order_review');
However, I want the order review and payment method sections to be separate, i.e. to call them individually in different places on the checkout page.
Solution attempt:
I came across guidance here and found the file includes/wc-template-hooks.php where the above action is created with he following code:
add_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
add_action('woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
So to test and call ONLY the payment section separately, I went back to form-checkout.php and tried this:
do_action( 'woocommerce_checkout_payment' );
or this
do_action( 'woocommerce_checkout_payment',99 );
But neither calls the payment section!
Could anyone please help me understand why this doesn't work?
Note: I know I can register hook the woocommerce_checkout_payment to a custom function and call it that way, but I'm confused as to why the direct method doesn't work and I'd prefer to keep things simple were possible.
Add this lines to functions.php in your child-theme:
// Detaching `payment` from `woocommerce_checkout_order_review` hook
remove_action('woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
// Attaching `payment` to my `woocommerce_checkout_payment_hook`
add_action('woocommerce_checkout_payment_hook', 'woocommerce_checkout_payment', 10 );
now you can use the custom hook to show the payment section:
do_action( 'woocommerce_checkout_payment_hook' );
P.S. Thank you #LoicTheAztec for the solution.
We use the Booster plugin which creates a unique WooCommerce order number such as WC-456544646. I now need to add the original order_id which still works in the background and with the WooCommerce API.
Booster provides a shortcode for the original order ID [wcj_order_id]
Here is the HTML for the custom Woo order number on the Edit Order page.
<h2 class="woocommerce-order-data__heading">
Order #WC-63872414 details</h2>
How can I insert a shortcode onto the 'Edit Order' page?
(Woocommerce/Orders/[Select Order/Order Details] eg /post.php?post=638&action=edit
I looked into Booster plugin code. It uses woocommerce_order_number filter hook to replace the order ID in WC edit order page and orders. In /woocommerce-jetpack/includes/class-wcj-order-numbers.php :
add_filter( 'woocommerce_order_number', array( $this, 'display_order_number' ), PHP_INT_MAX, 2 );
Since it's not passing the $instance of neither WCJ_Order_Numbers nor WC_Jetpack classes in any action hook, in order to remove this text and use a custom one, we can not use remove_filter function. So to override Booster plugin, we have to hook another function to woocommerce_order_number.
To add WC order_id to admin order pages:
add_action( 'admin_init', 'append_wc_order_id');
function append_wc_order_id()
{
add_filter('woocommerce_order_number', 'filter_wc_order_id', PHP_INT_MAX);
function filter_wc_order_id($order_id)
{
/* If you are using 'init' action hook, uncomment bellow line to apply this code only to your admin pages: */
//if (!is_admin()) return $order_id;
return $order_id . ' | #' . do_shortcode('[wcj_order_id]');
}
}
This code goes to your functions.php file of your theme.
Tested & Wordking:
Notes:
1. The filter hook in the Booster code, uses PHP_INT_MAX priority so in order to override this, we can not use bigger integer priority. Therefore I used admin_init action to hook my function to woocommerce_order_number, after other plugins done their job. It may function as you expected, without using init hooks, but it's not guaranteed. You can use init hook instead of admin_init to add the WC order_id on the front-end side of your site too (e.g. 'My Account' page). Read the comments inside the code.
2. To remove the order ID generated by Booster plugin on admin pages, you may change this line:
return $order_id . ' | #' . do_shortcode('[wcj_order_id]');
to:
return do_shortcode('[wcj_order_id]');
I need to move the Amazon Pay message/button on the checkout page in Woocommerce. We are using Amazon Pay by Woocommerce.
When I look at the plugin code I have determined that in the plugin's file /woocommerce-gateway-amazon-payments-advanced.php the message/button gets added using:
add_action( 'woocommerce_before_checkout_form', array( $this, 'checkout_message' ), 5 );
If I change 'woocommerce_before_checkout_form' to 'woocommerce_after_checkout_form' it moves. I have been struggling to figure out how to hook into the plugin from my functions.php.
The following worked for me:
function move_amazon_pay() {
remove_action( 'woocommerce_before_checkout_form', array( wc_apa(), 'checkout_message' ), 5 );
add_action( 'woocommerce_after_checkout_form', array( wc_apa(), 'checkout_message' ), 5 );
}
add_action( 'woocommerce_checkout_init', 'move_amazon_pay', 11 );
woocommerce_checkout_init must be at priority 11, because the Amazon Pay plugin adds the action at priority 10.
Use wc_apa() instead of $this because wc_apa() returns an instance of the WC_Amazon_Payments_Advanced class, allowing you to access the checkout_message method.
I am currently trying to add new custom emails to the woocommerce emails list.
I have followed the instructions from this link : https://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/
I use a custom action for this email (ch_deadline) which I trigger with this in my plugin:
add_action( 'ch_deadline_notification', array( $this, 'trigger' ) );
As I have seen in this post : WooCommerce - send custom email on custom order status change, I need to add it to the woocommerce email actions :
add_filter( 'woocommerce_email_actions', 'add_deadline_email_actions' ); // WC 2.3+
function add_deadline_email_actions( $email_actions ) {
$email_actions[] = 'ch_deadline';
return $email_actions;
}
In the front-end, it works well, it display my new email in the list.
Unfortunately the email has never been sent.
I have read a lot of post about this problem but none of the proposed solutions resolved the problem
I have even tried to add directly my action in $email_actions list in class-wc-emails.php
If you have any ideas, I'm more than interested !
Thanks !
When a User Buys a Product he can generate up to 3 Serial Keys for his Product. This works fine so far. The User can see his Serials always in "my account"
The Data gets stored in the Database: Table=Usermeta Meta=Product_Serial
So from a Users Perspective evrything works fine but from the Admin Perspective not because the admin canĀ“t see how much Serials the Customer has created and also he cant see the Serials the User is using.
Now I have created a Custom Field in the Theme functions.php with this code:
add_action( 'add_meta_boxes', 'add_meta_boxes' );
function add_meta_boxes()
{
add_meta_box(
'woocommerce-order-my-custom',
__( 'Order Custom' ),
'order_my_custom',
'shop_order',
'side',
'default'
);
}
But from here I don't know how to read out the Serial Key so the admin can see it. :( Any ideas ?
May be i am displaying data in wrong place in your order detail page. But you can check there is multipe hook avilable for this woocommerce/inculdes/admin/meta-boxes-/view/html-order-items.php.
I just take one this hook. Please add this code in functions.php
function my_function_meta_deta() {
echo "I am here";
}
add_action( 'woocommerce_admin_order_totals_after_refunded','my_function_meta_deta', $order->id );
As coder said there is multiple hooks you can also try this out.
add_action('woocommerce_admin_order_data_after_order_details', 'my_custom_order_manipulation_function');
function my_custom_order_manipulation_function( $orderID ) {
//dynamic functionalities / static html to display
}
Credits : Add order metadata to WooCommerce admin order overview