Introduction #
So, you’ve got your WordPress site all set up with the WooCommerce Wishlist plugin, and now you want to Customize PDF output to match your site’s style or just to make it look a bit more personalized. No worries, we’ve got you covered! With a few simple filters and a bit of code magic, you can customize the PDF output in no time. Let’s dive in:
Customize PDF Output Headings and Titles #
Step 1: Locate Your Functions.php File #
First things first, you’ll need to find your functions.php
file in your WordPress theme. If you’re using a child theme, you should edit the functions.php
file of your child theme. However, if you’re not using a child theme, you must add these customizations to your theme’s functions.php
directly.
Editing the child theme’s functions.php file is recommended over directly editing the parent theme’s functions.php. (Here’s why)
Alternative Method: Using a PHP Editor Plugin #
If you prefer not to directly edit the functions.php
file, you can use a PHP editor plugin available in the WordPress repository. These plugins provide a user-friendly interface for adding custom PHP code snippets to your site. Simply install the plugin of your choice, navigate to its settings or editor, and input the filter functions provided in this guide.
Step 2: Add Filter Functions #
Now that you’ve got your functions.php
file open, it’s time to add some filter functions to customize the PDF output. You’ll be using the add_filter()
function along with the specific filter hooks provided by the Wishlist plugin.
Customize Wishlist Title #
Let’s start with the Wishlist title. If you want to change the title displayed on your wishlist PDF, you can use the wlfmc_wishlist_title
filter. Here’s how:
add_filter('wlfmc_wishlist_title', 'customize_wlfmc_wishlist_title');
function customize_wlfmc_wishlist_title() {
return 'Your New Wishlist Title';
}
Adjust Product Name Heading #
If you want to adjust the heading for the product names displayed in the PDF, use the wlfmc_wishlist_pdf_view_name_heading
filter:
add_filter('wlfmc_wishlist_pdf_view_name_heading', 'wlfmc_customize_name_heading');
function wlfmc_customize_name_heading() {
return 'Custom Product Name Heading';
}
Modify Product Price Heading #
To modify the heading for the product prices shown in the PDF, you can use the wlfmc_wishlist_pdf_view_price_heading
filter:
add_filter('wlfmc_wishlist_pdf_view_price_heading', 'wlfmc_customize_price_heading');
function wlfmc_customize_price_heading() {
return 'Custom Product Price Heading';
}
Change Product Quantity Heading #
To change the heading for the product quantities listed in the PDF, utilize the wlfmc_wishlist_pdf_view_quantity_heading
filter:
add_filter('wlfmc_wishlist_pdf_view_quantity_heading', 'wlfmc_customize_quantity_heading');
function wlfmc_customize_quantity_heading() {
return 'Custom Product Quantity Heading';
}
Customize Stock Status Heading #
If you want to customize the heading for the product stock status displayed in the PDF, you can use the wlfmc_wishlist_pdf_view_stock_heading
filter:
add_filter('wlfmc_wishlist_pdf_view_stock_heading', 'wlfmc_customize_stock_heading');
function wlfmc_customize_stock_heading() {
return 'Custom Stock Status Heading';
}
Modify No Product Message #
Lastly, if you want to modify the text displayed when there are no products in the wishlist, you can use the wlfmc_no_product_in_wishlist_message
filter:
add_filter('wlfmc_no_product_in_wishlist_message', 'wlfmc_customize_no_product_message');
function wlfmc_customize_no_product_message() {
return 'Custom Message When Wishlist is Empty';
}
Step 3: Save the Settings #
Once you’ve added your desired filter functions to the functions.php
file, don’t forget to save your changes. Now, when you generate a PDF of your wishlist, you’ll see your customizations reflected in the output!
Customize PDF Columns and Layout #
Using the wlfmc_pdf_parameters
filter, you can customize which columns appear in the PDF output and adjust the width of each column. This allows you to tailor the PDF to your specific needs. For example, you can choose to include or exclude columns such as product image, product name, price, stock status, and more.
- Add the Filter FunctionInsert the following code into your theme’s
functions.php
file:add_filter( 'wlfmc_pdf_parameters', 'wlfmc_customize_pdf_columns' );
function wlfmc_customize_pdf_columns( $params ) {
$params['items_show'] = array(
'list-title',
'product-thumbnail',
'product-variation',
'product-name',
'product-stock-status',
'product-date-added',
'product-quantity',
'product-price',
'product-price-variation',
);
$params['column_widths'] = array(
'product-thumbnail' => '65px',
'product-name' => '340px',
'product-price' => '120px',
'product-quantity' => '65px',
'product-stock-status' => '75px',
'product-date-added' => '75px',
);
return $params;
} - Customize Displayed Columns
- To remove a column from the PDF, delete its corresponding entry in the
'items_show'
array. For example, to exclude the product thumbnail, remove'product-thumbnail'
from the array.
- To remove a column from the PDF, delete its corresponding entry in the
- Adjust Column Widths
- After removing a column, you can redistribute its width among the remaining columns by adjusting the values in the
'column_widths'
array. Ensure that the total width remains consistent to maintain the layout.
- After removing a column, you can redistribute its width among the remaining columns by adjusting the values in the
Add Product Meta Information to PDF #
If you need to print additional product details that are visible in the wishlist but not currently displayed in the PDF output, you can customize the PDF to include this meta information. This can be done using a custom action hook to modify the table data.
Steps to Add Product Meta to the PDF:
To include extra product meta details (such as custom attributes or other components) in the wishlist PDF, you can use the following code:
add_action( 'wlfmc_pdf_table_meta_data', 'wlfmc_customize_pdf_table_meta_data', 10, 3 );
function wlfmc_customize_pdf_table_meta_data( $meta, $cart_item, $wishlist ) {
do_action( 'wlfmc_before_wishlist_table', $wishlist, array() );
try {
$item_meta_date = apply_filters( 'wlfmc_item_meta_data', '', $meta, $cart_item, $wishlist );
$item_meta_date = '' !== wlfmc_remove_empty_html_tags( $item_meta_date ) ? $item_meta_date : '';
} catch ( Exception $e ) {
$item_meta_date = '';
}
do_action( 'wlfmc_after_wishlist_table', $wishlist, array() );
echo wp_kses_post( $item_meta_date );
}
wlfmc_pdf_table_meta_data
: This hook allows you to modify the meta data of the wishlist items that appear in the PDF output.wlfmc_item_meta_data
: This filter can be used to add or modify the item metadata that will be displayed.wlfmc_remove_empty_html_tags
: This function ensures that any empty HTML tags are removed before displaying the meta information.
Why Edit the Child Theme’s Functions or the Theme’s Functions.php? #
Editing the child theme’s functions.php
file is recommended over directly editing the parent theme’s functions.php
. Here’s why:
- Preservation of Customizations: If you ever update your parent theme, any customizations made directly to the
functions.php
file will be lost. By using a child theme, your customizations remain intact even after updating the parent theme. - Organizational Benefits: Keeping custom code separate in a child theme’s
functions.php
file helps in maintaining a cleaner and more organized codebase, making it easier to manage and debug. - Prevention of Theme Breakage: Directly modifying the parent theme’s files can lead to potential issues or theme breakage, especially if you’re not careful. Using a child theme provides a safe environment for making customizations without risking the stability of your site.
Conclusion #
That’s it! You’ve successfully customized the PDF output of your Wishlist plugin to better suit your site’s needs.
Feel free to explore these settings and tailor the PDF to your specific requirements. If you have any further questions or need assistance, don’t hesitate to reach out to our support team for help.