How to display Product Pros and Cons in WooCommerce
If you have configured "Plus and Minus points" (Pros and Cons) in StoreLinkr, these are automatically synchronized to WooCommerce as metafields.
Metafield Keys
The data is stored using the following keys:
- Pros (Positive points):
_positive_points - Cons (Negative points):
_negative_points
Displaying Pros and Cons on your Website
You can display these points anywhere on your product page. Below is an example of how to show them as a list under the product summary.
Example Code Snippet
add_action('woocommerce_single_product_summary', 'display_storelinkr_pros_cons', 25);
function display_storelinkr_pros_cons() {
global $product;
$pros = $product->get_meta('_positive_points');
$cons = $product->get_meta('_negative_points');
if (!empty($pros) || !empty($cons)) {
echo '<div class="product-pros-cons">';
if (!empty($pros)) {
echo '<div class="pros"><h4>Pros</h4>' . wpautop(esc_html($pros)) . '</div>';
}
if (!empty($cons)) {
echo '<div class="cons"><h4>Cons</h4>' . wpautop(esc_html($cons)) . '</div>';
}
echo '</div>';
}
}
Tips for Designers
- Styling: Use CSS to add checkmarks (green) for pros and crosses (red) for cons.
- Placement: You can change the priority (the
25in theadd_actioncall) to move the block higher or lower on the page. - Formatting: The metafields often contain multiple lines. The
wpautop()function in the example helps preserve line breaks.