Iam new to WooCommerce theming and get stuck with category display page here is the code i have:
/**
* Change several of the breadcrumb defaults
*/
add_filter('woocommerce_breadcrumb_defaults', 'jk_woocommerce_breadcrumbs');
function jk_woocommerce_breadcrumbs()
{
if (is_product_category()) {
global $wp_query;
// get the query object
$cat = $wp_query->get_queried_object();
// get the thumbnail id using the queried category term_id
$thumbnail_id = get_term_meta($cat->term_id, 'banner', true);
// get the image URL
$image = wp_get_attachment_url($thumbnail_id);
// print the IMG HTML
echo "";
return array(
'delimiter' => ' / ',
'wrap_before' => '<div class="c-main-banner c-main-banner--inner no-overlay w-100" style="background-image: url(' . $image . '"><div class="container"><ol>',
'wrap_after' => '</ol></div></div>',
'before' => '<li>',
'after' => '</li>',
'home' => _x('Home', 'breadcrumb', 'woocommerce'),
);
}
}
But i need to display like this:
<div class="c-main-banner c-main-banner--inner no-overlay w-100" style="background-image: url( category banner image as background );">
<div class="container">
<ol class="c-breadcrumb">
<li><a href="breadcrumb slug"> breadcrumb-name </a></li>
</ol>
<div class="c-banner-content d-flex align-items-start justify-content-end flex-wrap flex-column">
<big> woocommerce-products-header-title </big>
</div>
</div>
</div>
Iam new to WooCommerce theming and get stuck with category display page here is the code i have:
/**
* Change several of the breadcrumb defaults
*/
add_filter('woocommerce_breadcrumb_defaults', 'jk_woocommerce_breadcrumbs');
function jk_woocommerce_breadcrumbs()
{
if (is_product_category()) {
global $wp_query;
// get the query object
$cat = $wp_query->get_queried_object();
// get the thumbnail id using the queried category term_id
$thumbnail_id = get_term_meta($cat->term_id, 'banner', true);
// get the image URL
$image = wp_get_attachment_url($thumbnail_id);
// print the IMG HTML
echo "";
return array(
'delimiter' => ' / ',
'wrap_before' => '<div class="c-main-banner c-main-banner--inner no-overlay w-100" style="background-image: url(' . $image . '"><div class="container"><ol>',
'wrap_after' => '</ol></div></div>',
'before' => '<li>',
'after' => '</li>',
'home' => _x('Home', 'breadcrumb', 'woocommerce'),
);
}
}
But i need to display like this:
<div class="c-main-banner c-main-banner--inner no-overlay w-100" style="background-image: url( category banner image as background );">
<div class="container">
<ol class="c-breadcrumb">
<li><a href="breadcrumb slug"> breadcrumb-name </a></li>
</ol>
<div class="c-banner-content d-flex align-items-start justify-content-end flex-wrap flex-column">
<big> woocommerce-products-header-title </big>
</div>
</div>
</div>
Share
Improve this question
asked Feb 4, 2022 at 9:18
Dragan Petrovic FSDDragan Petrovic FSD
1
1 Answer
Reset to default 0I am supprised that this question still accepts answers once woocommerce is a plugin and out of the scope of this chat. Anyhow for what I have understood you want to show the product title on the woocommerce breadcrumb, Woocommerce breadcrumb already does that by default, there is no need of any changes, just remove your code.
woocommerce_breadcrumb();
If you really want to add to you function the product tittle, you can call it like this
global $product;
echo $product->name;
However this will only works on the product page, on the shop page and like so will not show the product name, or will only show the first product name.