In this comprehensive guide on how to display price changes in your Wishlist Table, you’ll discover the essential need for showcasing price changes. Understanding and visualizing price adjustments directly in the Wishlist Table is crucial for users seeking a dynamic and informed shopping experience.
The provided code snippet allows you to customize the display of prices in your Wishlist Table. By applying this filter, you can enhance the presentation of price information for products in your wishlist. Let’s break down the code and provide additional explanations.
How to Display Price Changes in the Wishlist Table: #
To Display Price Changes in the Wishlist Table, follow these steps:
- Access your WordPress theme’s directory.
- Locate the functions.php file.
- Insert the following code snippet into the functions.php file:
add_filter( 'wlfmc_item_formatted_price', 'wlfmc_separate_product_price', 10, 4 );
/**
* Change display price format.
*
* @param string $formatted_price formatted price.
* @param string $base_price base price.
* @param WC_Product $product product object.
* @param WLFMC_Wishlist_Item $item wlfmc wishlist item.
* @return string
*/
function wlfmc_separate_product_price( $formatted_price, $base_price, $product, $item ) {
$base_price = $product->is_type( 'variable' ) ? $product->get_variation_regular_price( 'max' ) : $product->get_price();
$meta = $item->get_product_meta( 'view' );
if ( is_array( $meta ) && isset( $meta['attributes'] ) ) {
unset( $meta['attributes'] );
}
if ( empty( $meta ) ) {
$formatted_price = $base_price ? $product->get_price_html() : ( '0' === $base_price ? apply_filters( 'wlfmc_free_text', esc_html__( 'Free!', 'wc-wlfmc-wishlist' ), $product ) : '' );
} else {
$base_price = $item->get_product_price( 'edit' );
$formatted_price = $base_price ? wc_price( $item->get_product_price( 'view' ) ) : ( '0' === $base_price ? apply_filters( 'wlfmc_free_text', esc_html__( 'Free!', 'wc-wlfmc-wishlist' ), $product ) : '' );
}
return $formatted_price;
}
- Save the functions.php file.
Result
Here you can see the result for this feature:

Explanation
The function wlfmc_separate_product_price
takes four parameters:
$formatted_price
: The original formatted price.$base_price
: The base price of the product.$product
: The WooCommerce product object.$item
: The Wishlist item object.
This function then customizes the formatted price based on the type of product (variable or not) and the presence of additional meta data in the Wishlist item. The resulting formatted price is then returned for display in the Wishlist Table.
Additional Customization Options: #
Hide Price Variations Using CSS #
If you want to hide price variations (e.g., for increased prices), you can do so using a simple CSS rule. Add the following CSS to your theme’s custom CSS section or a custom CSS plugin:
.wlfmc-wishlist-table .price-variation {
display: none !important;
}
This will hide the price variations in the wishlist table.
Customize Price Variation Template #
You can also customize the template or text for displaying price variations using the
wlfmc_price_variation_template
filter. This filter allows you to change the text or layout of the price variations:
add_filter( 'wlfmc_price_variation_template', 'customize_price_variation_template', 10, 2 );
function customize_price_variation_template( $template, $item ) {
// Modify the template as needed
$template = '<div class="custom-price-variation">' . esc_html__( 'Your Custom Price Variation Text', 'wc-wlfmc-wishlist' ) . '</div>';
return $template;
}
Feel free to integrate this code into your WooCommerce setup to enhance the presentation of prices within your wishlist feature. You can also Display SKU in Wishlist Table using this tutorial.