• Resolved marinow1991

    (@marinow1991)


    Photo —>> https://ibb.co/ZT4Y1GL

    Use this code to replace the product name with its SKU.

    Now I would like to add the size / name of the variation of the product sold.

    Can anybody help me ??

    function filter_order_item_get_name( $item_name, $order_item ) {
        if ( is_admin() && $order_item->is_type('line_item') ) {
            $product = $order_item->get_product();
    
            if( $sku = $product->get_sku() ) {
                $item_name = $sku;
            }
        }
        return $item_name;
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello there,

    Have you tried this code?

    It is highly recommended to use a plugin like Code Snippets to add custom PHP code into your site without directly accessing the functions.php file. Here is an article that explains how to use the Code Snippets plugin:

    https://www.wpbeginner.com/plugins/how-to-easily-add-custom-code-in-wordpress-without-breaking-your-site/

    Thread Starter marinow1991

    (@marinow1991)

    Hello this is code dont work for me

    Thread Starter marinow1991

    (@marinow1991)

    I found this code, which should do what I want, but it doesn’t work.

    add_filter( 'woocommerce_order_item_name', 'sku_before_order_item_name', 30, 3 );
    function sku_before_order_item_name( $item_name, $item, $is_visible ) {
        $product = $item->get_product();
        $sku = $product->get_sku();
    
        // When sku doesn't exist we exit
        if( empty( $sku ) ) return $item_name;
    
        $sku_text = __( 'SKU', 'woocommerce' ) . ': ' . $sku;
    
        // Add product permalink when argument $is_visible is true
        $product_permalink =  $is_visible ? $product->get_permalink( $item ) : '';
    
        if( $product_permalink )
            return sprintf( '<a href="%s">%s - %s</a>', $product_permalink, $sku_text, $item->get_name() );
        else
            return $sku_text . ' - ' . $item->get_name();
    }

    @marinow1991

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.
    
    I can also recommend <a href="https://developer.woocommerce.com/" rel="noopener" target="_blank">the WooCommerce Developer Resources Portal</a> for resources on developing for WooCommerce.
    
    You can also visit the <a href="https://www.facebook.com/groups/advanced.woocommerce/" rel="noopener" target="_blank">WooCommerce Facebook group</a> or the <code>#developers</code> channel of the <a href="https://woocommerce.com/community-slack/" rel="noopener" target="_blank">WooCommerce Community Slack</a>. We're lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – we’ll be here if and/or when you are ready to continue.

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Replace product name by SKU and variation name in Woocommerce admin orders pages’ is closed to new replies.