Color Strings in Item name

[ad_1]

Hi @donzzzzz,

You can not apply scripts within the PDF documents, but you can achieve the same with this code snippet, that I just wrote for you:

/**
 * PDF Invoices & Packing Slips for WooCommerce:
 * Highlight specific words in the item names
 */
add_filter( 'wpo_wcpdf_html_filters', function( $filters ) {
	$filters[] = array( 'woocommerce_order_item_name', 'wpo_wcpdf_hihglight_item_name', 999, 3 );
	return $filters;
} );
function wpo_wcpdf_hihglight_item_name( $item_name, $item, $is_visible ) {
    $item_names_to_highlight = array(
        /* Set the word(s) to search and the color to apply, one per line */
        '(Gluten)' => 'red',
        '(Free)' => 'green',
        '(string3)' => 'blue',
    );
    foreach ( $item_names_to_highlight as $target => $color) {
        if ( strpos( $item_name, $target ) !== false ) {
            $item_name = str_replace( $target,  "<span style=\"color: {$color};\">{$target}</span>", $item_name );
        }
    }
	return $item_name;
}

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

 

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