Untitled
webwizards
plain_text
10 months ago
1.7 kB
19
Indexable
add_filter('b2bking_quote_item_cart', 'add_pricing_to_quote_item', 10, 2);
function add_pricing_to_quote_item($messagecart, $values) {
$product = wc_get_product($values['data']->get_id());
if (!$product) {
return $messagecart;
}
// Get user's current price (what they see)
if ($product->is_on_sale()) {
$current_price = $product->get_sale_price();
} else {
$current_price = $product->get_price();
}
// Get original standard prices from database
$product_id = $product->get_id();
$regular_price = get_post_meta($product_id, '_regular_price', true);
$sale_price = get_post_meta($product_id, '_sale_price', true);
// Format prices for display
$current_price_formatted = !empty($current_price) ? wc_price($current_price) : wc_price(0);
$regular_price_formatted = !empty($regular_price) ? wc_price($regular_price) : __('N/A', 'b2bking');
// Build pricing information
$pricing_info = '<br>';
$pricing_info .= '<span style="font-size: 0.9em; color: #666;">';
$pricing_info .= __('Current Price: ', 'b2bking') . $current_price_formatted . ' | ';
$pricing_info .= __('Standard Price: ', 'b2bking') . $regular_price_formatted;
// Add sale price if it exists and is different from current price
if (!empty($sale_price) && $sale_price != $current_price) {
$sale_price_formatted = wc_price($sale_price);
$pricing_info .= ' | ' . __('Sale Price: ', 'b2bking') . $sale_price_formatted;
}
$pricing_info .= '</span>';
// Add pricing info to the message
$messagecart .= $pricing_info;
return $messagecart;
}Editor is loading...
Leave a Comment