hide/display product attributes with action hooks – not working
-
Hi Ewout,
I want to make some changes to our invoices, specifically hide the product weight, and instead print tariff number & country of origin. (_dhl_hs_code, _dhl_manufacture_country).
I found plenty of info that you had previously shared, but none of the scripts worked for me.
I put this in the php – it had no effect.
/* dont show weight on invoice*/
function wpo_wcpdf_custom_styles ( $document_type, $document ) {
?>
.meta .weight { display:none !important; } <?php
}Another attempt- with no effect
add_action(‘wpo_wcpdf_after_item_meta’, ‘wpo_wcpdf_show_custom_attribute’, 10, 3);
function wpo_wcpdf_show_custom_attribute($document_type, $item, $order)
{
if( !empty($order) && $document_type == ‘invoice’ ) {
$product = wc_get_product($item[‘product_id’]);
$attributes = $product->get_attributes();
foreach( $attributes as $type => $attribute ) {
if( $type == ‘_dhl_hs_code’ ) { // attribute type
echo ‘<dl class=”meta”>’;
echo ‘<dt class=”_dhl_hs_code”>’.$attribute[‘name’].’:</dt><dd”>’.$attribute[‘options’][0].'</dd>’;
echo ‘</dl>’;
}
}
}
}And this script was rejected, the ‘return’ in line 4 caused an error:
add_action( ‘wpo_wcpdf_after_item_meta’, ‘wpo_wcpdf_show_product_attributes’, 10, 3 );
function wpo_wcpdf_show_product_attributes ( $template_type, $item, $order ) {
if(empty($item[‚product’])) return;
$document = wcpdf_get_document( $template_type, $order );
printf(‘<div class=„product-attribute“>_dhl_hs_code: %s</div>’, $document->get_product_attribute(‚_dhl_hs_code‚, $item[‘product’]));
}Can you tell me what I am doing wrong? As you can see I have no experience in coding and don’t know how to modify the commands.
Thanks!
Anja MC
The topic ‘hide/display product attributes with action hooks – not working’ is closed to new replies.
