Filter woocommerce_email_actions - php

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 !

Related

How To Use do_shortcode with WooCommerce One Page Checkout

I'm trying to use the WordPress do_shortcode function for the WooCommerce One Page Checkout Plugin which uses shortcode like this: [woocommerce_one_page_checkout template="product-table" product_ids="product, ids, here"]. It seems like I can only use this shortcode IF it's in the content editor and won't allow me to add this to a page template using the do_shortcode function.
Their documentation here says:
If you wish to display the One Page Checkout Shortcode using WordPress’ do_shortcode() function instead of including the shortcode in a post or page’s content, you will also need to attach custom code to the 'is_wcopc_checkout' filter and make sure a boolean true value is returned.
So I tried adding the following to the functions.php file:
add_filter( 'is_wcopc_checkout', function(){ return true; } );
and it didn't seem to do the trick.
I also tried:
add_filter( 'is_wcopc_checkout', 'my_one_page_checkout' );
function my_one_page_checkout(){
return true;
}
add_filter( 'is_wcopc_checkout', 'true' );
That didn't seem to do it either.
Am I adding this code to the functions.php wrong? Any help on how I can get the One Page Checkout Plugin to work using do_shortcode?
Here's my full code in the page template for reference:
<?php
echo do_shortcode('[woocommerce_one_page_checkout template="product-table" product_ids="62, 122, 438, 52, 433, 435, 512, 514"]');
?>
Thanks for your help.
(I tried contacting WooCommerce support and they were no help saying that this is custom code and they can't do anything to help.)
The simplest way to return a true to a filter is like sitting the call back to WP default __return_true. So the function will be like
add_filter( 'is_wcopc_checkout', '__return_true' );
There is no filter named is_wcopc_checkout in the code of WooCommerce one page checkout version 1.0.2
From their doc- You can also manually add a shortcode [woocommerce_one_page_checkout] to any page or post and use the shortcode's attributes.
Usage: [woocommerce_one_page_checkout product_ids="30,45,12"]
Some context from One page checkout readme.
To register your template, attach a callback to the 'wcopc_templates' filter and add a new array of your template's details to the $templates array passed to your function.
For example, to register a custom pricing table template, the code would be similar to:
function eg_add_opc_template( $templates ) {
$templates['my-custom-pricing-table'] = array(
'label' => __( 'My Pricing Table', 'eg' ),
'description' => __( "Display a sophisticated and colourful pricing table with each product's attributes, but not weight or dimensions.", 'eg' ),
);
return $templates;
}
add_filter( 'wcopc_templates', 'eg_add_opc_template' ) );
The key used in the $templates array should be the template's file name (excluding the extension). The label element of the array is the name displayed on the One Page Checkout dialog. The description element is used for the tooltip next to the template's name.

Woocommerce checkout page has unconfigurable fields

I am stuck with trying to configure my website's checkout fields in woo commerce.It comes prefilled with values and doesnt get removed even after purging the cache.
https://shinujohn.com/checkout/ ...set as with the default shortcode
The country has 2 field boxes now...one is clickable drop down.
Server side caching is disabled.
The theme I'm using is Kallyas
I Have tried:-
Field editor : It does not even show the field ..say company name.and adding a new field is not reflected here.even if i add it to the billing or checkout fields
Adding code to functions.php
/returning woo commerce field as blank/
add_filter('woocommerce_checkout_get_value','__return_empty_string', 1, 1);
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
add_filter( 'woocommerce_billing_fields' , 'custom_override_billing_fields' );
or
function custom_override_billing_fields( $fields ) {
unset($fields['billing_postcode']);
unset($fields['billing_state']);
unset($fields['billing_country']);
unset($fields['billing_address_1']);
return $fields;
}
neither work
3. issue persists with multiple browsers and unlogged users in different machines..
4. Within the theme's page editor... i can of course change front end ...but it doesnt reflect it after publishing.
I don't recommend you to use any extra plugin to edit the Woocommerce checkout fields. Here is the simple solution that you can easily customize the Woocommerce checkout fields.
add_filter( 'woocommerce_checkout_fields' , 'custom_override_billing_fields', 5);
function custom_override_billing_fields( $fields ) {
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_address_1']);
return $fields;
}
May this code helps you.

Woocommerce show related products in order emails

I am looking for a way to add a section to my order emails in Woocommerce to show related products. I have already customized the php templates for my emails, but cannot seem to find the right code snippet to call the related products function.
I tried the solution in the thread without succes:
How to add related products or cross sells to order emails in WooCommerce
Any suggestions?
You can use this hook woocommerce_email_after_order_table to show text after order table.
add_action( 'woocommerce_email_after_order_table', 'add_order_email_instructions', 10, 2 );
function add_order_email_instructions( $order, $sent_to_admin ) {
if ( ! $sent_to_admin ) {
echo 'Custom HTml OR Custom Text';
}
}

Trigger email on order custom status change in Woocommerce

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.

Show Custom Data in Woocommerce Order Details Admin Area

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

Categories