1

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
        }
}
Simo
  • 71
  • 1
  • 8

1 Answers1

1

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:

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Hello, your code work well, but without icons, is there any possibility to add an image instead of icons, and also I wanted to add another class called 'xc_ajax_button' – Simo Apr 22 '18 at 13:28
  • As you can see in screenshot, there is font icons on the buttons that are set in the last function… I have addes the 2 links for Woocommerce and Wordpress available icons (visual + icon code). I have added other related answers links. **Now, for your other class called 'xc_ajax_button'** you'll have to try to adapt it in the functions code, as I can't test anything related (or ask a new question, giving more explanations, details and all related code). – LoicTheAztec Apr 22 '18 at 14:05
  • I added the class 'xc_ajax_button' and I changed some stuff in the code all I wanted is to get the img url, I will ask a new question or I will edit that page – Simo Apr 22 '18 at 14:58
  • @Simo There is no images url for woocommerce actions buttons in backend order list… it has to be an icon font… So you should better ask a new question. – LoicTheAztec Apr 22 '18 at 16:08
  • Thanks, I just added the icon, in your code you wrote a wrong class (wc-action-button-), I don't have this class in my button, I changed the class name and I added another point and then everything is working well, anyway thank you so much for your help – Simo Apr 22 '18 at 16:59
  • @Simo this was for Woocommerce version 3.3 (as in my screenshot) which has a different class… So I have updated my code adding Woocommerce compatibility versions. – LoicTheAztec Apr 22 '18 at 17:13