/**
 * WooCommerce 产品分类页标题和面包屑
 * 目标：
 * 1. 去掉 Archive Title 前缀“分类：”
 * 2. 产品分类页面包屑只显示：Home > 当前分类
 * 3. 提供短代码给 Elementor 使用
 */

/**
 * 产品分类页标题短代码
 * 用法：[custom_product_archive_title]
 */
function custom_product_archive_title_shortcode() {
    if ( is_shop() ) {
        return 'Shop';
    }

    if ( is_product_category() ) {
        $current_term = get_queried_object();

        if ( $current_term && ! is_wp_error( $current_term ) && isset( $current_term->name ) ) {
            return esc_html( $current_term->name );
        }
    }

    return get_the_title();
}
add_shortcode( 'custom_product_archive_title', 'custom_product_archive_title_shortcode' );

/**
 * WooCommerce Breadcrumb
 * 产品分类页只显示：Home > 当前分类
 */
add_filter( 'woocommerce_get_breadcrumb', 'custom_product_category_breadcrumb_home_and_current_only' );
function custom_product_category_breadcrumb_home_and_current_only( $crumbs ) {
    if ( is_product_category() ) {
        $current_term = get_queried_object();

        if ( $current_term && ! is_wp_error( $current_term ) && isset( $current_term->name ) ) {
            $crumbs = array(
                array( 'Home', home_url( '/' ) ),
                array( $current_term->name, '' ),
            );
        }
    }

    if ( is_shop() ) {
        $crumbs = array(
            array( 'Home', home_url( '/' ) ),
            array( 'Shop', '' ),
        );
    }

    return $crumbs;
}

/**
 * 自定义产品分类页面包屑短代码
 * 用法：[custom_product_breadcrumb]
 */
function custom_product_breadcrumb_shortcode() {
    if ( is_product_category() ) {
        $current_term = get_queried_object();

        if ( $current_term && ! is_wp_error( $current_term ) && isset( $current_term->name ) ) {
            $home_url  = home_url( '/' );
            $home_text = 'Home';
            $current   = esc_html( $current_term->name );

            return '<a href="' . esc_url( $home_url ) . '">' . $home_text . '</a> &gt; ' . $current;
        }
    }

    if ( is_shop() ) {
        $home_url  = home_url( '/' );
        $home_text = 'Home';

        return '<a href="' . esc_url( $home_url ) . '">' . $home_text . '</a> &gt; Shop';
    }

    return '';
}
add_shortcode( 'custom_product_breadcrumb', 'custom_product_breadcrumb_shortcode' );
require HELLO_THEME_PATH . '/theme.php';

HelloTheme\Theme::instance();<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://mufabric.com/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://mufabric.com/wp-sitemap-posts-post-1.xml</loc></sitemap><sitemap><loc>https://mufabric.com/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://mufabric.com/wp-sitemap-posts-product-1.xml</loc></sitemap><sitemap><loc>https://mufabric.com/wp-sitemap-taxonomies-category-1.xml</loc></sitemap><sitemap><loc>https://mufabric.com/wp-sitemap-taxonomies-product_cat-1.xml</loc></sitemap><sitemap><loc>https://mufabric.com/wp-sitemap-users-1.xml</loc></sitemap></sitemapindex>
