Pour créer un nouveau statut de commande et envoyer un e-mail personnalisé sur votre boutique woocommerce.
dans Woocommerce-wordpressPour créer un nouveau statut de commande et envoyer un e-mail personnalisé sur votre boutique woocommerce.
/* Ajout status de commande perso et envoi d'emails */
// register a custom post status 'ready-pickup' for Orders
add_action( 'init', 'register_custom_post_status', 20 );
function register_custom_post_status() {
register_post_status( 'wc-ready-pickup', array(
'label' => _x( 'Prête à emporter', 'Order status', 'woocommerce' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Prête à emporter <span class="count">(%s)</span>', 'Prête à emporter <span class="count">(%s)</span>', 'woocommerce' )
) );
}
// Adding custom status 'ready-pickup' to order edit pages dropdown
add_filter( 'wc_order_statuses', 'custom_wc_order_statuses', 20, 1 );
function custom_wc_order_statuses( $order_statuses ) {
$order_statuses['wc-ready-pickup'] = _x( 'Prête à emporter', 'Order status', 'woocommerce' );
return $order_statuses;
}
// Adding custom status 'ready-pickup' to admin order list bulk dropdown
add_filter( 'bulk_actions-edit-shop_order', 'custom_dropdown_bulk_actions_shop_order', 20, 1 );
function custom_dropdown_bulk_actions_shop_order( $actions ) {
$actions['mark_ready-pickup'] = __( 'Marquer Prête à emporter', 'woocommerce' );
return $actions;
}
// Adding action for 'ready-pickup'
add_filter( 'woocommerce_email_actions', 'filter_woocommerce_email_actions');
function filter_woocommerce_email_actions( $actions ) {
$actions[] = 'woocommerce_order_status_wc-ready-pickup';
return $actions;
}
//add_action( 'woocommerce_order_status_wc-ready-pickup', array( WC(), 'send_transactional_email' ), 10, 1 );
// Sending an email notification when order get 'ready-pickup' status
add_action('woocommerce_order_status_ready-pickup', 'backorder_status_custom_notification', 20, 2);
function backorder_status_custom_notification_old($order_id, $checkout=null) {
global $woocommerce;
$order = new WC_Order( $order_id );
if($order->status === 'ready-pickup' ) {
// Create a mailer
$mailer = $woocommerce->mailer();
$message_body = __( 'Hello world!!!' );
$message = $mailer->wrap_message(
// Message head and message body.
sprintf( __( 'Order %s received' ), $order->get_order_number() ), $message_body
);
// Cliente email, email subject and message.
$mailer->send( $order->billing_email, sprintf( __( 'Order %s received' ), $order->get_order_number() ), $message );
}
}
function backorder_status_custom_notification( $order_id, $order ) {
// custom settings
$heading = __('Votre commande est prête !','woocommerce');
//$subject = '[{site_title}] Votre commande est prête ({order_number}) - {order_date}';
$subject = 'Votre commande est prête !';
// Getting all WC_emails objects
$mailer = WC()->mailer()->get_emails();
// Customizing Heading and subject In the WC_email processing Order object
$mailer['WC_Email_Customer_Processing_Order']->heading = $heading;
$mailer['WC_Email_Customer_Processing_Order']->settings['heading'] = $heading;
$mailer['WC_Email_Customer_Processing_Order']->subject = $subject;
$mailer['WC_Email_Customer_Processing_Order']->settings['subject'] = $subject;
$mailer['WC_Email_Customer_Processing_Order']->template_html = 'emails/ready-pickup.php';
$mailer['WC_Email_Customer_Processing_Order']->template_plain = 'emails/plain/ready-pickup.php';
// Sending the customized email
$mailer['WC_Email_Customer_Processing_Order']->trigger( $order_id );
}