簡體   English   中英

WooCommerce 管理訂單列表中發送客戶發票的操作按鈕

[英]Action button in WooCommerce admin orders list that send the customer invoice

在 Wordpress 管理儀表板中,當您打開 woocommerce 訂單頁面時,您將看到訂單列表和列(訂單、日期、狀態、賬單、運輸、總計、操作

我想為操作列表添加一個新按鈕,然后添加此操作以將 Email 發票發送給訂單仍處於暫停狀態的客戶。

在此處輸入圖像描述

我創建了如下列和按鈕,但我無法調用操作按鈕將每個訂單的發票發送給客戶。

請指教。

add_filter( 'woocommerce_admin_order_actions', 'add_custom_order_status_actions_button', 100, 2 );
function add_custom_order_status_actions_button( $actions, $order ) {

    if ( $order->has_status( array( 'on-hold' ) ) ) {

        // The key slug defined for your action button
        $action_slug = 'invoice';
        $status = $_GET['status'];
        $order_id = method_exists($the_order, 'get_id') ? $the_order->get_id() : $the_order->id;
        // Set the action button
        $actions[$action_slug] = array(
            'url'       => admin_url('post.php?post=' . $post_id . '&action=edit&message=11'),
            'name'      => __( 'Invoice', 'woocommerce' ),
            'action'    => $action_slug,
        );
    }
    return $actions;
}

add_action( 'admin_head', 'add_custom_order_status_actions_button_css' );
function add_custom_order_status_actions_button_css() {
    $action_slug = "invoice"; // The key slug defined for your action button
    echo '<style>.wc-action-button-'.$action_slug.'::after { font-family: woocommerce !important; content: "\e029" !important; }</style>';
}

已更新(添加缺失'

下面將在管理訂單列表操作列中為處於“暫停”狀態的訂單添加一個操作按鈕。 該按鈕通過管理員 Ajax 發送客戶發票通知。

完整代碼:

add_filter( 'woocommerce_admin_order_actions', 'add_admin_order_custom_actions_button', 100, 2 );
function add_admin_order_custom_actions_button( $actions, $order ) {
    if ( $order->has_status( array( 'on-hold' ) ) ) {
        // The key slug defined for your action button
        $action_slug = 'email_invoice';

        // Set the action button
        $actions[$action_slug] = array(
            'url'    => wp_nonce_url(
                admin_url('admin-ajax.php?action=send_invoice_email&order_id=' . $order->get_id() ),
                'send-invoice-email'
            ),
            'name'   => __( 'Send Invoice', 'woocommerce' ),
            'action' => $action_slug,
        );
    }
    return $actions;
}

add_action( 'wp_ajax_send_invoice_email', 'trigger_customer_email_invoice' );
function trigger_customer_email_invoice() {
    if ( current_user_can('edit_shop_orders') && check_admin_referer('send-invoice-email') &&
    isset($_GET['order_id']) && get_post_type( absint( wp_unslash($_GET['order_id']) ) ) === 'shop_order' ) {
        $order_id = absint( wp_unslash($_GET['order_id']) );

        WC()->mailer()->get_emails()['WC_Email_Customer_Invoice']->trigger($order_id); // Send email
        update_post_meta( $order_id, '_invoice_sent', 'OK' ); // For testing purpose (to be removed)
    }
}

add_action( 'admin_head', 'add_custom_order_status_actions_button_css' );
function add_custom_order_status_actions_button_css() {
    $action_slug = "email_invoice"; // The key slug defined for your action button
    echo '<style>.wc-action-button-'.$action_slug.'::after { font-family: woocommerce !important; content: "\e02d" !important; }</style>';
}

代碼進入活動子主題(或活動主題)的 functions.php 文件。 測試和工作。

在 Wordpress 管理儀表板中,當您打開 woocommerce 訂單頁面時,您將看到訂單列表,列是(訂單、日期、狀態、賬單、運輸、總計、操作

我想為操作列表添加一個新按鈕,然后添加此操作以將 Email 發票發送給仍處於暫停狀態的客戶。

在此處輸入圖像描述

我已經創建了如下的列和按鈕,但是我無法調用操作按鈕將發票發送給每個訂單的客戶。

請指教。

add_filter( 'woocommerce_admin_order_actions', 'add_custom_order_status_actions_button', 100, 2 );
function add_custom_order_status_actions_button( $actions, $order ) {

    if ( $order->has_status( array( 'on-hold' ) ) ) {

        // The key slug defined for your action button
        $action_slug = 'invoice';
        $status = $_GET['status'];
        $order_id = method_exists($the_order, 'get_id') ? $the_order->get_id() : $the_order->id;
        // Set the action button
        $actions[$action_slug] = array(
            'url'       => admin_url('post.php?post=' . $post_id . '&action=edit&message=11'),
            'name'      => __( 'Invoice', 'woocommerce' ),
            'action'    => $action_slug,
        );
    }
    return $actions;
}

add_action( 'admin_head', 'add_custom_order_status_actions_button_css' );
function add_custom_order_status_actions_button_css() {
    $action_slug = "invoice"; // The key slug defined for your action button
    echo '<style>.wc-action-button-'.$action_slug.'::after { font-family: woocommerce !important; content: "\e029" !important; }</style>';
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM