Created
April 11, 2025 11:33
-
-
Save webtoffee-git/d96157d04a3e4f0b294f27c01d5f7be3 to your computer and use it in GitHub Desktop.
To alter webp product image size in invoice document for mPDF add-on users - By WebToffee (WooCommerce PDF Invoice, Packing Slips, Delivery Notes and Shipping labels)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //do not copy this line of code | |
add_filter('wf_pklist_alter_product_table_columns', 'wt_pklist_alter_product_image_size', 10, 5); | |
add_filter('wf_pklist_alter_package_product_table_columns', 'wt_pklist_alter_product_image_size', 10, 5); | |
function wt_pklist_alter_product_image_size($product_row_columns, $template_type, $_product, $order_item, $order) { | |
if ('invoice' === $template_type) { | |
$image_id = $_product->get_image_id(); | |
if ($image_id) { | |
$image_url = wp_get_attachment_url($image_id); | |
if ($image_url) { | |
// Use fixed width and height in pixels for mPDF compatibility | |
$image = '<img src="' . esc_url($image_url) . '" width="100" height="100" style="object-fit:contain;" />'; | |
$product_row_columns['image'] = $image; | |
} | |
} | |
} | |
return $product_row_columns; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment