Shorten the SKU | WordPress.org

[ad_1]

Hi @redair,

Try this code snippet I just wrote for you:

/**
 * PDF Invoices & Packing Slips for WooCommerce:
 * Limits the number of characters of the product SKU
 */
add_filter( 'wpo_wcpdf_html_filters', function( $filters ) {
	$filters[] = array( 'wpo_wcpdf_order_item_data', 'wpo_wcpdf_trim_long_sku', 999, 3 );
	return $filters;
} );
function wpo_wcpdf_trim_long_sku( $data, $order, $document_type ) {
	$char_limit = 10; // Set your desire limit here
	$data['sku'] = substr( $data['sku'], 0, $char_limit );
	return $data;
}

If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

I have set 10 as a limit within $char_limit, but feel free to edit this value with the one you like, to limit the number of characters to be displayed.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer