• Resolved frank0080

    (@frank0080)


    Hello guys!

    Thank you for creating this beautiful plugin. I recently changed the product titles by adding some keywords for SEO reasons. I prefer if SEO optimised product titles are not visible on the invoice or product slips. Would you be possible to set another product title that will be visible on the invoice instead of the original product title?

    Your help is much appreciated.

    The page I need help with: [log in to see the link]

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

    (@yordansoares)

    Hi @frank0080,

    Although it is possible to customize the item titles on the PDF invoice, it is not complete clear to me what you want to achieve, so here are some questions for you, so I can understand better and provide you with accurate advice:

    • Do you want to set custom names for the PDF documents manually, for each product in your inventory? This would be easier, but you would need to set the names one by one for each product, which could be exhausting if you have a lot of products.
    • If the answer to the previous question is ?No?: Could you please explain what would be the logic to rename the items? Maybe are you using a common pattern for the SEO titles that can be overridden or get rid with a regex, or a similar approach?
    Thread Starter frank0080

    (@frank0080)

    Hi Yordan,

    Thanks for your quick reply and apologies for the confusion. I’d like to set a custom name for the product only. We only have four products so shouldn’t take too long for us.

    Do you mind explaining further how to achieve this?

    Once again, thanks a lot!

    Best regards,

    Frank

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Thanks for providing more details, @frank0080:

    To customize the item names, you can use the woocommerce_order_item_name filter hook, using $item to get the product ID and override the item name.

    Actually, I went ahead and write the following code snippet for you:

    /**
    * PDF Invoices & Packing Slips for WooCommerce:
    * Set custom names for the specific items in the PDF Invoices
    */
    add_filter( 'wpo_wcpdf_html_filters', function( $filters, $document ) {
    if ( 'invoice' === $document->get_type() ) {
    $filters[] = array( 'woocommerce_order_item_name', 'wpo_wcpdf_custom_item_names', 999, 2 );
    }
    return $filters;
    }, 10, 2 );
    function wpo_wcpdf_custom_item_names( $item_name, $item ) {
    if ( $product = $item->get_product() ) {
    // Set the product IDs and custom names below,
    // with the following patter: 'product ID' => 'Custom name'
    $custom_product_names = array(
    '123' => 'Product Title 1',
    '456' => 'Product Title 2',
    '789' => 'Product Title 3',
    );

    foreach ( $custom_product_names as $product_id => $custom_name ) {
    if ( $product->get_id() === $product_id ) {
    $item_name = $custom_name;
    }
    }
    }
    return $item_name;
    }

    You only have to replace the product IDs with the actual ones, and set your custom names for each of them.

    Thread Starter frank0080

    (@frank0080)

    Hey Yordan!

    Wow, that is very kind of you. Thanks a thousand times!

    Have a great day!

    Best,

    Frank

    Thread Starter frank0080

    (@frank0080)

    Hi Yordan,

    We implemented the provided code successfully for the invoices. We’d like to do the same for the packing slips. Is this something you could help me with???

    appreciate your reply!

    best regards,

    Frank

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @frank0080,

    I’m sorry for taking so long to reply. It seems I lost track of this topic, as it was marked as ‘Resolved’—likely by me!

    I have removed the document check, so the code is applied to both the invoice and packing slip:

    /**
    * PDF Invoices & Packing Slips for WooCommerce:
    * Set custom names for the specific items in the PDF documents
    */
    add_filter( 'wpo_wcpdf_html_filters', function( $filters, $document ) {
    $filters[] = array( 'woocommerce_order_item_name', 'wpo_wcpdf_custom_item_names', 999, 2 );
    return $filters;
    }, 10, 2 );
    function wpo_wcpdf_custom_item_names( $item_name, $item ) {
    if ( $product = $item->get_product() ) {
    // Set the product IDs and custom names below,
    // with the following patter: 'product ID' => 'Custom name'
    $custom_product_names = array(
    '123' => 'Product Title 1',
    '456' => 'Product Title 2',
    '789' => 'Product Title 3',
    );

    foreach ( $custom_product_names as $product_id => $custom_name ) {
    if ( $product->get_id() === $product_id ) {
    $item_name = $custom_name;
    }
    }
    }
    return $item_name;
    }

    Let me know if you need anything else!

    Thread Starter frank0080

    (@frank0080)

    No worries Yordan, I am already happy you are helping me out. Thanks a lot for adjusting the code. I forwarded it to my programmer. I assume it will be all good now, but if not; then I will drop a message here.

    Have a great day ahead!

    Best regards,

    Frank

    Plugin Contributor Yordan Soares

    (@yordansoares)

    No problem, @frank0080:

    Take your time and let me know if you need more help! ??

    Thread Starter frank0080

    (@frank0080)

    Sorry for the late notice, but it worked Yordan!

    Once again, thanks a lot for your help!

    Have a great day!

    Plugin Contributor Yordan Soares

    (@yordansoares)

    I’m glad to hear that, @frank0080!

    If you don’t mind and have the time, do you think you could leave us a review?

    Thanks in advance and all the best with your store!

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.