Untitled
unknown
plain_text
2 years ago
1.5 kB
9
Indexable
add_action('woocommerce_before_shop_loop_item_title', 'custom_sale_badge_for_b2b_users', 10);
add_action('woocommerce_before_single_product_summary', 'custom_sale_badge_for_b2b_users', 10);
function custom_sale_badge_for_b2b_users() {
global $product;
$product_id = $product->get_id();
$current_user_group_id = b2bking()->get_user_group(get_current_user_id());
// Retrieve the custom prices for the current user group
$regular_price = get_post_meta($product_id, 'b2bking_regular_product_price_group_' . $current_user_group_id, true);
$sale_price = get_post_meta($product_id, 'b2bking_sale_product_price_group_' . $current_user_group_id, true);
$tiered_price = get_post_meta($product_id, 'b2bking_product_pricetiers_group_' . $current_user_group_id, true);
// Check if any of the prices are not empty
if (!empty($regular_price) || !empty($sale_price) || !empty($tiered_price)) {
echo '<span class="custom-sale-badge">Special Price</span>'; // Customize this HTML as needed
}
}
// Optional: Add custom styles for the badge
add_action('wp_head', 'custom_sale_badge_styles');
function custom_sale_badge_styles() {
?>
<style>
.custom-sale-badge {
position: absolute;
top: 10px;
left: 0;
background-color: #ff0000;
color: #ffffff;
padding: 5px 10px;
font-size: 12px;
z-index: 10;
}
</style>
<?php
}Editor is loading...
Leave a Comment