• Resolved vierthom

    (@vierthom)


    Hi Ewout, what a great plugin! thank you.
    I was able to add extra custom fields to the invoice by adding the snippet:

    // add additional product attributes to invoice HS TARIFF CODE

    add_action( ‘wpo_wcpdf_after_item_meta’, ‘wpo_wcpdf_product_custom_field’, 10, 3 );
    function wpo_wcpdf_product_custom_field ( $template_type, $item, $order ) {
    // check if product exists first
    if (empty($item[‘product’])) return;

    // replace ‘Location’ with your custom field name!
    $field_name = ‘hstariff’;
    $hstariff = $item[‘product’]->get_meta($field_name,true,’edit’);
    if (!empty($hstariff)) {
    echo ‘<div class=”product-location”>HS Tariff Code: ‘.$hstariff.'</div>’;
    }
    // replace ‘Location’ with your custom field name!
    $field_name = ‘country_origin’;
    $country_origin = $item[‘product’]->get_meta($field_name,true,’edit’);
    if (!empty($country_origin)) {
    echo ‘<div class=”product-location”>Country of Origin: ‘.$country_origin.'</div>’;
    }
    }

    But this extra lines are in a different font and fontsize than the SKU and Weight information just above these lines. You must have a trick to get it all in the same font?

    Thomas

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Yordan Soares

    (@yordansoares)

    Hello @vierthom,

    Try this code instead:

    // Custom Fields
    add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_product_custom_field', 10, 3 );
    function wpo_wcpdf_product_custom_field ( $template_type, $item, $order ) {
      // check if product exists first
      if (empty($item['product'])) return;
      
      // Display 'hstariff' if exists
      $field_name = 'hstariff';
    	$hstariff = $item['product']->get_meta($field_name,true,'edit');	
      if (!empty($hstariff)) {
        echo '<div class="hstariff">HS Tariff Code: '.$hstariff.'</div>';
      }
      // Display 'country_origin' if exists
      $field_name = 'country_origin';
    	$country_origin = $item['product']->get_meta($field_name,true,'edit');	
      if (!empty($country_origin)) {
        echo '<div class="country-origin">Country of Origin: '.$country_origin.'</div>';
      }
    }
    
    // Styles
    add_action( 'wpo_wcpdf_custom_styles', 'wpo_wcpdf_custom_styles', 10, 2 );
    function wpo_wcpdf_custom_styles ( $document_type, $document ) {
        ?>
        div.hstariff,
        div.country-origin {
            font-size: 7pt;
        }
        <?php
    }

    See also Using custom styles.

    Let me know if work!

    Thread Starter vierthom

    (@vierthom)

    Works like a charm! thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Extra Custom Fields’ is closed to new replies.