drxzpo70788179614 2018-04-20 22:58
浏览 61
已采纳

将图像添加到Woocommerce的管理顺序列表中的自定义操作按钮

Is there any way to get the img src in Woocommerce admin order list: That is the code of my PDF button, I just want to get the src image, I have two buttons 'Invoice' and 'Packing Slip', I want every button to get an image

// 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
        }
}
  • 写回答

1条回答 默认 最新

  • douzhuo6931 2018-04-21 00:52
    关注

    Try the following (based on your question code)

    // 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>';
    }
    

    Code goes in function.php file of your active child theme (or active theme). Tested and works, it should work for you too.

    enter image description here


    Woocommerce and Wordpress available icons: (visual + icon code):


    Similar related answers:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于线性结构的问题:希望能从头到尾完整地帮我改一下,困扰我很久了
  • ¥30 3D多模态医疗数据集-视觉问答
  • ¥20 设计一个二极管稳压值检测电路
  • ¥15 内网办公电脑进行向日葵
  • ¥15 如何输入双曲线的参数a然后画出双曲线?我输入处理函数加上后就没有用了,不知道怎么回事去掉后双曲线可以画出来
  • ¥50 WPF Lidgren.Network.Core2连接问题
  • ¥15 soildworks装配体的尺寸问题
  • ¥100 有偿寻云闪付SDK转URL技术
  • ¥30 基于信创PC发布的QT应用如何跨用户启动后输入中文
  • ¥20 非root手机,如何精准控制手机流量消耗的大小,如20M