• Resolved peterhso

    (@peterhso)


    Hi, thanks for a great plugin. I have one small problem, I use the WooCommerce Brands plugin for brand management, and I need the brand to be shown in the Packing list PDF. Its really just a plugin that adds Brands to its own category so it does not need to be shown with the rest. I have added brands to the email that goes ut with this code:

    function modfuel_woocommerce_before_order_add_cat($name, $item){
    $product_id = $item[‘product_id’];
    $_product = wc_get_product( $product_id );
    $htmlStr = “”;
    $brands = “”;
    $terms = get_the_terms( $product_id, ‘product_brand’ );
    $count = 0;
    foreach ( $terms as $term) {
    $count++;
    if($count > 1){
    $brands .= $term->name;
    }
    else{
    $brands .= $term->name . ‘,’;
    }
    }
    $brands = rtrim($brands,’,’);
    $htmlStr .= $_product->get_title();
    $htmlStr .= “<p>Brand: ” . $brands . “</p>”;
    return $htmlStr;
    }

    Can the same be done to the PDF in some way?

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

    (@pomegranate)

    Hi!
    You can indeed add this to the PDF with a code snippet:

    
    add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_show_product_brands', 10, 3 );
    function wpo_wcpdf_show_product_brands ( $template_type, $item, $order ) {
        if ($template_type != 'packing-slip') {
            return;
        }
        if (isset($item['product'])) {
            if ( $item['product']->is_type( 'variation' ) ) {
                $product_id = method_exists( $item['product'], 'get_parent_id' ) ? $item['product']->get_parent_id() : wp_get_post_parent_id( $item['product']->get_id() );
            } else {
                $product_id = $item['product']->get_id();
            }
    
            $brand_count = sizeof( get_the_terms( $product_id, 'product_brand' ) );
    
            $taxonomy = get_taxonomy( 'product_brand' );
            $labels   = $taxonomy->labels;
    
            echo '<div class="brands">';
            echo get_brands( $product_id, ', ', ' <span class="posted_in">' . sprintf( _n( '%1$s: ', '%2$s: ', $brand_count ), $labels->singular_name, $labels->name ), '</span>' );
            echo '</div>';
        }
    }
    

    Just in case anyone else is reading this and has not worked with code snippets like this before, check our documentation here: How to use filters

    Let us know if you have any other questions!
    Ewout

    Thread Starter peterhso

    (@peterhso)

    Thank you, that worked great!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to add Brands to PDF’ is closed to new replies.