簡體   English   中英

將img添加到Woocommerce的管理訂單列表中的自定義操作按鈕

[英]Add img to custom action buttons in admin order list for Woocommerce

有什么方法可以在Woocommerce管理員訂單列表中獲取img src:那是我的PDF按鈕的代碼,我只想獲取src圖像,我有兩個按鈕“發票”和“裝箱單”,我希望每個按鈕獲得圖像

// Add custom action buttons in woocommerce order list
add_filter( 'woocommerce_admin_order_actions', 'add_custom_print_actions_buttons', 100, 2 );
function add_custom_print_actions_buttons( $actions, $order ) {
    $opts = get_option('xc_woo_cloud_print_options', array());

    //if (isset($opts['printer']) && $opts['printer'] != "") {
        $domain = 'woocommerce-pdf-invoices-packing-slips';

        $slugs_label_names = array(
            'invoice'       => __('Invoice', $domain ),
            'packing-slip'  => __('Packing Slip', $domain )
        );

        // Set the action button
        foreach ( $slugs_label_names as $slug => $label_name ) {
            $actions[$slug] = array(
                'url'       => wp_nonce_url( admin_url( "admin-ajax.php?action=xc_woo_printer_job&document_type={$slug}&order_id=" . $order->get_id()), 'xc_woo_printer_job'),
                'alt' => esc_attr("Print " . $label_name),
                'title' => "Print " . $label_name
                'img' =>

            );
        }
    //}
 $actions = apply_filters('xc_woo_printer_meta_box_actions', $actions, $post_id);

    foreach ($actions as $document_type => $data) {
            ?>
            <a href="<?php echo $data['url']; ?>" class="button tips xc_ajax_button <?php echo $document_type; ?>" target="_blank" alt="<?php echo $data['alt']; ?>" data-tip="<?php echo $data['alt']; ?>">
                    <img src="<?php echo $data['img']; ?>" alt="<?php echo $data['alt']; ?>" width="16">
            </a>
            <?php
        }
}

嘗試以下操作(根據您的問題代碼)

// Add your custom action buttons
add_filter( 'woocommerce_admin_order_actions', 'add_custom_print_actions_buttons', 100, 2 );
function add_custom_print_actions_buttons( $actions, $order ) {
    $opts = get_option('xc_woo_cloud_print_options', array());

    if (isset($opts['printer']) && $opts['printer'] != "") {
        $domain = 'woocommerce-pdf-invoices-packing-slips';

        $slugs_label_names = array(
            'invoice'       => __('Invoice', $domain ),
            'packing-slip'  => __('Packing Slip', $domain )
        );

        // Set the action button
        foreach ( $slugs_label_names as $slug => $label_name ) {
            $actions[$slug] = array(
                'url'       => wp_nonce_url( admin_url( "admin-ajax.php?action=xc_woo_printer_job&document_type={$slug}&order_id=" . $order->get_id()), 'xc_woo_printer_job'),
                'name'      => $label_name,
                'action'    => $slug,
            );
        }
    }

    return $actions;
}

// Set Here the WooCommerce icon for your action button
add_action( 'admin_head', 'add_custom_print_actions_buttons_css' );
function add_custom_print_actions_buttons_css() {
    $slug_icons = array(
        'invoice'       => '\f497', // '\e02b',
        'packing-slip'  => '\f491', // '\e028',
    );
    // Added Woocommerce compatibility version
    $class  = version_compare( WC_VERSION, '3.3', '<' ) ? '.view.' : '.wc-action-button-';

    echo '<style>';

    foreach ( $slug_icons as $slug => $icon_code )
        echo $class.$slug.'::after { font-family: dashicons !important; content: "'.$icon_code.'" !important; font-size:1.4em !important; margin-top: -4px !important; }';

    echo '</style>';
}

代碼進入您的活動子主題(或活動主題)的function.php文件中。 經過測試和工作,它也應該為您工作。

在此處輸入圖片說明


Woocommerce和Wordpress可用的圖標 :( 可視+圖標代碼)


類似的相關答案:

暫無
暫無

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

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