Skip to content

Instantly share code, notes, and snippets.

@Werninator
Created April 4, 2018 13:48
Show Gist options
  • Save Werninator/cd1b6b51100d163bea280bd7ac7e6a54 to your computer and use it in GitHub Desktop.
Save Werninator/cd1b6b51100d163bea280bd7ac7e6a54 to your computer and use it in GitHub Desktop.
WooCommerce Germanized: Add String before Item / Product Title in PDF
<?php
// add this snippet to your functions.php if you want this kind of funcitonality
function add_something_before_invoice_item_name($name, $item) {
// getting category terms
$terms = get_the_terms($item->get_product_id(), 'product_cat');
// if this product has the category "Premium", it will be prepended to the name
foreach ($terms as $term)
if ($term->name === 'Premium')
return 'Premium: ' . $name;
// otherwise the name will be passed down unedited
return $name;
}
// adding the filter
add_filter( 'woocommerce_gzdp_invoice_item_name', 'add_something_before_invoice_item_name', 10, 99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment