Untitled
webwizards
plain_text
2 months ago
2.9 kB
4
Indexable
// CHANGE 0 left in stock to OUT OF STOCK
add_filter('b2bking_order_form_not_available_text', function($text, $productobj, $qtyaddable) {
return esc_html__('Out of Stock', 'b2bking');
}, 10, 3);
// HIDE FILTERS
add_action('wp_head', function(){
?>
<style>
.b2bking_orderform_filters {
display: none !important;
}
.b2bking_bulkorder_form_container_content_header_top.b2bking_bulkorder_form_container_content_header_top_cream.b2bking_orderform_cart {
width: 13%;
}
.b2bking_bulkorder_form_container_content_header_top.b2bking_bulkorder_form_container_content_header_top_cream:not(.b2bking_orderform_cart) {
width: 87%;
flex-direction: row-reverse;
}
.b2bking_bulkorder_cream_search_icon.b2bking_bulkorder_cream_search_icon_show.b2bking_bulkorder_cream_search_icon_search {
margin-right: 17px;
}
/*
.b2bking_brand_header_row{
width:100%;
padding: 8px 12px;
font-weight:bold;
background:#f0f0f0;
border-bottom: 1px solid #ddd;
}
*/
.b2bking_brand_header_row{
width:100%;
padding: 8px 12px;
font-weight:bold;
margin: 30px 0px;
}
</style>
<?php
});
// HEADERS
add_action('b2bking_before_orderform_cream_product', function($product_id) {
static $last_brand = null;
$taxonomy = 'product_brand';
$terms = get_the_terms($product_id, $taxonomy);
$brand_name = (!empty($terms) && !is_wp_error($terms)) ? $terms[0]->name : 'Other';
if ($brand_name !== $last_brand) {
$last_brand = $brand_name;
echo '<div class="b2bking_brand_header_row">'
. esc_html($brand_name)
. '</div>';
}
});
// FILTER by brand, and then alphabetically inside each brand
add_filter('b2bking_orderform_product_ids_before_processing', function($allTheIDs) {
if (empty($allTheIDs) || !is_array($allTheIDs)) {
return $allTheIDs;
}
// Change 'pa_brand' to your actual brand/category taxonomy slug.
// Common options: 'pa_brand', 'product_cat', 'pwb-brand' (Perfect WooCommerce Brands), etc.
$taxonomy = 'product_brand';
$products_data = [];
foreach ($allTheIDs as $product_id) {
$terms = get_the_terms($product_id, $taxonomy);
$brand_name = (!empty($terms) && !is_wp_error($terms))
? strtolower($terms[0]->name)
: 'zzz_uncategorized'; // push brandless products to the end
$product_title = strtolower(get_the_title($product_id));
$products_data[] = [
'id' => $product_id,
'brand' => $brand_name,
'title' => $product_title,
];
}
// Sort by brand alphabetically, then by product title within each brand
usort($products_data, function($a, $b) {
$brand_cmp = strcmp($a['brand'], $b['brand']);
if ($brand_cmp !== 0) {
return $brand_cmp;
}
return strcmp($a['title'], $b['title']);
});
return array_column($products_data, 'id');
});
Editor is loading...
Leave a Comment