I am trying to show the purchase note beneath the product in the customer_processing_order email that Woocommerce generates.
I have added the following to my functions.php file:
function sww_add_images_woocommerce_emails( $output, $order ) {
// set a flag so we don't recursively call this filter
static $run = 0;
// if we've already run this filter, bail out
if ( $run ) {
return $output;
}
$args = array(
'show_purchase_note' => true,
);
// increment our flag so we don't run again
$run++;
// if first run, give WooComm our updated table
return $order->email_order_items_table( $args );
}
add_filter( 'woocommerce_email_order_items_table', 'sww_add_images_woocommerce_emails', 10, 2 );
This works, however it is printing an error message in the email stating the following:
"Notice: WC_Order::email_order_items_table is deprecated since version
3.0! Use wc_get_email_order_items instead. in /nas/content/staging/ishgamultisite/wp-includes/functions.php on line
3853"
if I change woocommerce_email_order_items_table to wc_get_email_order_items the function doesn't work.
I'm hoping someone can tell me how I should modify the code as I'm not sure?
Bit late but if anybody is still needing to show purchase notes, then there's an easier hook:
/**
* PURCHASE NOTE
* Edits the email order items args to show purchase notes
*/
function ag_add_wc_order_email_purchase_notes( $args ) {
$args['show_purchase_note'] = true;
return $args;
}
add_filter( 'woocommerce_email_order_items_args', 'ag_add_wc_order_email_purchase_notes', 10, 1 );
The filter woocommerce_email_order_items_args contains the arguments for what to display in the order emails.
$array — Optional. (callback) => array( 'order' => $order, 'items' => $order->get_items(), 'show_download_links' => $order->is_download_permitted() && ! $args['sent_to_admin'], 'show_sku' => $args['show_sku'], 'show_purchase_note' => $order->is_paid() && ! $args['sent_to_admin'], 'show_image' => $args['show_image'], 'image_size' => $args['image_size'], 'plain_text' => $args['plain_text'], 'sent_to_admin' => $args['sent_to_admin'], )
Source: http://hookr.io/filters/woocommerce_email_order_items_args/
Tested with WooCommerce 3.6.2 and works fine.
replace return $order->email_order_items_table( $args );
with
return wc_get_email_order_items( $order, $args );
Related
I need to put custom BACS field in the Thank you page and also for the emails. My country needs 'variable symbol' for the BACS method, which would be the order number. I dont want to change core files.
This is what i do:
add_filter( 'woocommerce_bacs_account_fields', 'custom_bacs_account_field', 10, 2);
function custom_bacs_account_field( $account_fields, $order_id ) {
$account_fields['variable_symbol'] = array(
'label' => 'Variabilní symbol',
'value' => $order_id
);
return $account_fields;
}
For some reason this displays the variable symbol twice.
Thank you!
Alright so this works for me:
add_filter( 'woocommerce_bacs_account_fields', 'custom_bacs_account_field', 10, 2);
function custom_bacs_account_field( $account_fields, $order_id ) {
static $call_counter = 0;
if ( $call_counter>0 ) {
return $account_fields;
}
$account_fields['variable_number' ] = array(
'label' => 'Variabliní symbol',
'value' => $order_id
);
$call_counter++;
return $account_fields;
}
I have a wordpress site where users can upload products. The default product status is pending,however I want to change it to published if it has passed 12 hours after the post_time.
I am using woocommerce.
I´ve tried to use wp_insert_post_data:
function reset_post_date_wpse_121565($data,$postarr) {
if ($data['post_type'] == 'product'){
$data['post_date'] = '2018-06-03 22:50:00';
}
return $data;
}
add_filter('wp_insert_post_data','reset_post_date_wpse_121565');
But it sets the post to published, what can I do to accomplish this auto update?
You can try WordPress Cron run to achieve this,
function myprefix_custom_cron_schedule( $schedules ) {
$schedules['every_tewlve_hours'] = array(
'interval' => 43200, // Every 12 hours
'display' => __( 'Every 12 hours' ),
);
return $schedules;
}
add_filter( 'cron_schedules', 'myprefix_custom_cron_schedule' );
//Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'myprefix_cron_hook' ) ) {
wp_schedule_event( time(), 'every_tewlve_hours', 'myprefix_cron_hook' );
}
///Hook into that action that'll fire every six hours
add_action( 'myprefix_cron_hook', 'myprefix_cron_function' );
//create your function, that runs on cron
function myprefix_cron_function() {
$args = array(
'numberposts' => -1,
'post_type' => 'product',
'post_status' => array( 'pending' ),
'author' => $userid
);
$pending_posts = get_posts( $args );
//update status code
}
Hope this will helps you.
For more example visit,
wp cron demo
I'd like show images product in a new order and completed an order for customers.
I tried this code, but show big images in email, I need eg 100 x 100 px
function sww_add_wc_order_email_images( $table, $order ) {
ob_start();
$template = $plain_text ? 'emails/plain/email-order-items.php' : 'emails/email-order-items.php';
wc_get_template( $template, array(
'order' => $order,
'items' => $order->get_items(),
'show_download_links' => $show_download_links,
'show_sku' => $show_sku,
'show_purchase_note' => $show_purchase_note,
'show_image' => true,
'image_size' => array( 100, 50 ),
'image_size' => $image_size
) );
return ob_get_clean();
}
add_filter( 'woocommerce_email_order_items_table', 'sww_add_wc_order_email_images', 10, 2 );
I don't know if you already fixed this issue. I'm new here at StackOverflow and saw this question when looking for some other stuff :)
But I've just added this simple snippet to my functions.php:
/**
* Display Product Image in WooCommerce Order Emails
*
* #author James Kemp (Iconic)
*/
add_filter( 'woocommerce_email_order_items_args', 'iconic_email_order_items_args', 10, 1 );
function iconic_email_order_items_args( $args ) {
$args['show_image'] = true;
return $args;
}
I've created a custom wordpress plugin in which I'm defining a custom post type and at one point I'm calling add_action to set custom column in the admin.
The 'manage_[custompostname]_posts_columns' is working great, but the 'manage_[custompostname]_posts_custom_column' do not.
add_filter('manage_bbc_cp_game_posts_columns', bbc_cp_game_table_head');
function bbc_cp_game_table_head( $defaults ) {
$columns = array(
'team_id' => 'Equipe',
'opponent_id' => 'Adversaire',
'gamedatetime' => 'Date / heure',
'score' => 'Score'
);
return $columns;
}
add_action( 'manage_bbc_cp_game_posts_custom_column', 'bbc_cp_game_table_content', 10, 2 );
function bbc_cp_game_table_content( $column, $post_id ) { die('it should work'); }
The second add_action returns true, but the function is never called.
I'd really appreciate if any of you had an idea of what could be the issue, or how to debug it.
Thanks,
I'm trying to automatically exclude all articles that don't have a custom field set. I have checked the 'instant_articles_before_render_post' and 'instant_articles_after_render_post' hooks but I wonder how I could use them to prevent the render of the article. Any ideas?
instant_articles_before_render_post and instant_articles_after_render_post are used to launch actions before / after the post rendering but cannot prevent the post to render. What you need to do is to hook on pre_get_posts in order to change the main query used by Facebook Instant Articles.
If you look in the facebook-instant-articles.php plugin file, you will see the following function:
function instant_articles_query( $query ) {
if ( $query->is_main_query() && $query->is_feed( INSTANT_ARTICLES_SLUG ) ) {
$query->set( 'orderby', 'modified' );
$query->set( 'posts_per_page', 100 );
$query->set( 'posts_per_rss', 100 );
/**
* If the constant INSTANT_ARTICLES_LIMIT_POSTS is set to true, we will limit the feed
* to only include posts which are modified within the last 24 hours.
* Facebook will initially need 100 posts to pass the review, but will only update
* already imported articles if they are modified within the last 24 hours.
*/
if ( defined( 'INSTANT_ARTICLES_LIMIT_POSTS' ) && INSTANT_ARTICLES_LIMIT_POSTS ) {
$query->set( 'date_query', array(
array(
'column' => 'post_modified',
'after' => '1 day ago',
),
) );
}
}
}
add_action( 'pre_get_posts', 'instant_articles_query', 10, 1 );
You can hook right after this and add your own meta condition like this:
function instant_articles_query_modified($query) {
if($query->is_main_query() && isset(INSTANT_ARTICLES_SLUG) && $query->is_feed(INSTANT_ARTICLES_SLUG)) {
$query->set('meta_query', array(
array(
'key' => 'your_required_meta'
)
));
}
add_action('pre_get_posts', 'instant_articles_query_modified', 10, 2);
Thanks. The code above didn't quite work because it's missing a closing } and the isset caused a problem.
Try this:
function instant_articles_query_modified($query) {
if($query->is_main_query() && null!==INSTANT_ARTICLES_SLUG && $query->is_feed(INSTANT_ARTICLES_SLUG)) {
$query->set('meta_query', array(
array(
'key' => 'your_required_meta'
)
));
}
}