How to display product condition (New/Used) in WooCommerce
StoreLinkr can synchronize the condition of a product (New or Used) to WooCommerce. This data is stored in a metafield and can be displayed on your product pages using a simple code snippet.
Prerequisite
Ensure that your data source (e.g., your POS system or PIM) provides product condition data and that StoreLinkr is configured to read it.
Implementation Code
Add the following snippet to your theme's functions.php file or a custom plugin to display the condition on the single product page:
add_action('woocommerce_single_product_summary', function() {
global $product;
if (!$product instanceof WC_Product) {
return;
}
// Retrieve the 'used' meta field
$condition_code = $product->get_meta('used');
if ($condition_code !== '' && $condition_code !== null) {
// Mapping:
// 0 = New
// 1 = Used
$label = ($condition_code == 1) ? 'Used' : 'New';
echo '<p class="product-condition"><strong>Condition:</strong> ' . esc_html($label) . '</p>';
}
}, 15);
How it works
StoreLinkr saves the condition as a numeric value in the used metafield:
0: New1: Used
By using get_meta('used'), you can access this value and translate it into a user-friendly label for your customers. You can further customize the CSS class .product-condition to match your theme's design.