Skip to content

Instantly share code, notes, and snippets.

@cesjam7
Created January 4, 2022 04:36
Show Gist options
  • Save cesjam7/3712f0053caf805914d64f778a1a9fe6 to your computer and use it in GitHub Desktop.
Save cesjam7/3712f0053caf805914d64f778a1a9fe6 to your computer and use it in GitHub Desktop.
Estado personalizado para woo con envío de mail
<?php // register a custom post status 'payment-confirmed' for Orders
add_action( 'init', 'register_custom_post_status', 20 );
function register_custom_post_status() {
register_post_status( 'wc-payment-confirmed', array(
'label' => _x( 'Pago confirmado', '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( 'Pago confirmado <span class="count">(%s)</span>', 'Pago confirmado <span class="count">(%s)</span>', 'woocommerce' )
) );
if (function_exists('acf_add_options_page')) {
$parent = acf_add_options_page(array(
'page_title' => 'Configuración',
'menu_title' => 'Configuración',
'menu_slug' => 'configuracion',
'redirect' => false
));
}
}
// Adding custom status 'payment-confirmed' 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-payment-confirmed'] = _x( 'Pago confirmado', 'Order status', 'woocommerce' );
return $order_statuses;
}
// Adding custom status 'payment-confirmed' 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_payment-confirmed'] = __( 'Mark Pago confirmado', 'woocommerce' );
return $actions;
}
// Adding action for 'payment-confirmed'
add_filter( 'woocommerce_email_actions', 'custom_email_actions', 20, 1 );
function custom_email_actions( $action ) {
$actions[] = 'woocommerce_order_status_wc-payment-confirmed';
return $actions;
}
if ( class_exists( 'WooCommerce' ) ) {
add_action( 'woocommerce_order_status_wc-payment-confirmed', array( WC(), 'send_transactional_email' ), 10, 1 );
}
// Sending an email notification when order get 'payment-confirmed' status
add_action('woocommerce_order_status_payment-confirmed', 'backorder_status_custom_notification', 20, 2);
function backorder_status_custom_notification( $order_id, $order ) {
// HERE below your settings
$heading = __('Tu orden - Pago confirmado','woocommerce');
$subject = 'Hemos confirmado tu pago - {order_number}';
// 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']->subject = $subject;
// Sending the customized email
$mailer['WC_Email_Customer_Processing_Order']->trigger( $order_id );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment