I am trying to cancel/remove the automatic customer emails that are sent when saving order status as "completed" after the order was shipped.
The reason for not wanting automatic emails to be sent is because I added a a code to the email template file (override) /woocommerce/email/customer-completed-order.php which will display the new order note created in the admin in the email sent to the customer and if we add the order note and save it and then change the order status to completed and save it, a new note is created and an email is sent. So now the note showing in the email sent to the customer is not the note that we wanted to display in the email.
The entire intention of this is to have a nicely designed email with status update "shipped" and include the tracking number of the shipment.
The code that adds the last/newest order note to the email:
<?php
$args = array(
'status' => 'approve',
'post_id' => $order->id
);
$comments = get_comments($args);
foreach($comments as $comment) {
if ($comment === reset ($comments))
echo $comment->comment_content . '.<br />';
}
So I now found a solution for this.
Adding the function from this link:
https://docs.woocommerce.com/document/unhookremove-woocommerce-emails/
add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );
function unhook_those_pesky_emails( $email_class ) {
remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );
}
The above function will disable the automatic email that is sent when saving the order with the status "completed" but you can still manually send the order completed email using the "order actions" and control which last order note is saved while sending the email.
So now we simply change the order status to completed and save, then we add an "order note to customer" (not private) which only contains the tracking number and save it ("add note") and lastly we use the "order actions" to manually send the order completed email to the customer.
Feel free if any questions...
The entire intention of this is to have a nicely designed email with
status update "shipped" and include the tracking number of the
shipment.
I recommend creating your own order status and calling it shipped. Here's how to make it all work: WooCommerce - send custom email on custom order status change
I had a similar issue but resolved it differently:
We disabled the automatic email that is sent once the order is completed (in WC>settings>emails) so no email is sent out when the order is marked completed.
We then changed the email template of the order notes to our desired text (e.g. "Your order has now been completed and is on it's way to you. Please find below the tracking numbers for your shipment") and use the note function for the tracking numbers. They don't link to the tracking website directly but with the shipping agents detailed provided in the template it should be easy for the customer to manually copy and paste for tracking.
Would that work for you?
<?php
$args = array(
'status' => 'approve',
'post_id' => $order->id
);
$comments = get_comments($args);
foreach($comments as $comment)
{
if ($comment === reset ($comments))
echo $comment->comment_content . '.<br />';
}
The above code does not give the desired output(i.e. the last order note to the customer) in WooCommerce(WC) 3.1.0
The working of the above code was due to a bug which was fixed in WC 3.1.0. For the above code to work(to return the last order note to the customer) do the following:
remove the code line: $comments = get_comments($args);
and replace it with:
`remove_filter( 'comments_clauses', array( 'WC_Comments','exclude_order_comments' ), 10, 1 );
$comments = get_comments( $args );
add_filter( 'comments_clauses', array( 'WC_Comments','exclude_order_comments' ), 10, 1 );`
Fo more details on the bug :https://github.com/woocommerce/woocommerce/issues/15982#issuecomment-313235066
Related
i tried to look everywhere for several hours and could not find anything relevant to what i want.
Is there any way to send one more detail in email for new order when BACS was choosen? This detail must have same formatting as rest of the bank details like SWIFT code or account number and would be named "Variabilný symbol" with result of order number.
this is what i have now all bank details set in woocommerce BACS payment settings
https://snipboard.io/ybu0vk.jpg
and i would like to add one more information which would always be the order number with same formatting.
I have solution if anyone would be interested:
add_filter( 'woocommerce_bacs_account_fields', 'custom_bacs_account_field', 10, 2);
function custom_bacs_account_field( $account_fields, $order_id ) {
$order = wc_get_order( $order_id );
$account_fields['variable_symbol' ] = array(
'label' => 'NAME FOR THE LABEL GOES HERE',
'value' => $order->get_order_number()
);
return $account_fields;
}
i am not author of this code.
How can this situation be done?
Wordpress install at ABC.com.
Wordpress install at 123.com.
A new member signs up at abc.com, then instantly and automatically, the same user's email address and password be programmatically inserted into 123.com. After the abc.com sign up process is completed, the new user is redirected to log in at 123.com.
How to achieve that?
you can achieve your functionality using two tricks, firstly you have to connect your wordpress with second DB.
global $wpdb;
$newdb = new wpdb( 'USERNAME' , 'PASSWORD' , 'DATABASE NAME' , 'HOST' );
$newdb->show_errors();
Then you can use the user_register hook to get all data from user upon registration AND update them to new database as a user.
add_action( 'user_register', 'myplugin_registration_save', 10, 1 );
function myplugin_registration_save( $user_id ) {
//print_r($_POST); // to get all information of user
// Insert data in other database
$newdb->insert('wp_users', array(
'display_name' => $_POST['first_name'],
'user_email' => $_POST['user_email'],
'user_phone' => $_POST['user_phone'], // ... and so on
));
}
Haven't tried this code but it will work.
I am developing this plugin that admin can add a user in the backend and when user is created, plugin can automatically generate one custom post which I have added to the theme. The custom post will store user ID that is just created (or if it is possible make that user an author of the post)
I wonder if what I have mentioned above is possible practically. If anybody has any better advice, I am open for any suggestions.
Thank you in advance
I'm not sure that a unique custom post type per user is the best way to implement what you're wanting to achieve. If you have 100 users, you will have 100 custom post types making the wp-admin a nightmare as the left menu would grow with so many menu-items.
Wouldn't it be easier to just use a normal post type and then have the page that shows the user's dashboard filter the posts to only show posts where the user is the post_author? You could then add a hook to catch when a user registers and create the example post, you could modify the code below and add it to your functions.php:
add_action( 'user_register', 'myplugin_registration_save', 10, 1 );
function myplugin_registration_save( $user_id ) {
$userPostsCategory = 3;
// Create post object
$my_post = array(
'post_title' => 'Sample Story' ),
'post_content' => 'You can edit this or create a new story',
'post_status' => 'publish',
'post_author' => user_id,
'post_category' => array( $userPostsCategory )
);
// Insert the post into the database
wp_insert_post( $my_post );
}
This method will lower the number of customisations you'd have to do to your themes and make management of the posts a little easier.
Further reading on this:
User registration hook
Inserting a post using wp_insert_post
I have changed the default permalink of my website to Custom permalink (/%post-name%)
Now all posts require slug values .
which is not present currently.A slug is automatically added when a post is published or updated if slug screen option is unable ,but in my case now i have unable the slug option for all post earlier this was disabled and Now I want to update each post nothing want to add or delete just want to update all posts .
Currently number of posts in database is 200000,
Please suggest any efficient query or any method so that my task can be accomplished.
Thanks,
Monika
Try this plugin, it should do the job:
http://www.jerrytravis.com/598/wordpress-plugin-to-generate-post-slugs
Also this chunk of code can do the job, but you have to add some limits to avoid the script to crash due to the max limit of execution:
// get all posts
$posts = get_posts( array ( 'numberposts' => -1 ) );
foreach ( $posts as $post )
{
// check the slug and run an update if necessary
$new_slug = sanitize_title( $post->post_title );
wp_update_post(
array (
'ID' => $post->ID,
'post_name' => $new_slug
)
);
}
Credit for the code:
https://wordpress.stackexchange.com/questions/46086/regenerate-slugs-from-title-of-posts
I'm writing a plug-in in which I'm updating a post content and create a custom field using
add_post_meta($post->ID, 'thesis_post_image', 'http://www.nurseryrhymesonline.net/images/' . $meta);
$my_post = array(
'ID' => $post->ID,
'post_content' => $cont
);
wp_update_post( $my_post );
It is working fine and the content and the custom fields are exactly as I wanted BUT although I can see the content and the custom field at the post edit page it seems like not updating the DB unless I manually hit the Update button.
I tried without any success have a new loop in which I changing the post status to 'draft' and back to 'published' and also to 'private' and back to 'published' and even 'pending' and back BUT nothing helped and it doesn't simulate the manual clicking on the update button.
Any Idea how to simulate clicking on Update button from a plug-in
I've found in the past that using $post->ID does not work very well in a plugin. Maybe get_the_id() will help. Codex here.