$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>WooCommerce breadcrumb display custom posts instead of product data|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

WooCommerce breadcrumb display custom posts instead of product data

matteradmin9PV0评论

I'm working on a custom theme with some additional features for my store. To gather all promotions in one place in my store back-end and front-end, I created custom post type, custom taxonomy for it. The code for it is:

/**
*
* Registering custom post type 'promocja'
*
**/
function missplanner_promotion_post_type() {

    /**
    * UI Labels
    **/
    $custom_post_labels = array(
        'name'               => _x( 'Promocje', 'post type general name', 'missplanner-official' ),
        'singular_name'      => _x( 'Promocje', 'post type singular name', 'missplanner-official' ),
        'menu_name'          => _x( 'Promocje', 'admin menu', 'missplanner-official' ),
        'name_admin_bar'     => _x( 'Dodaj promocję', 'add new on admin bar', 'missplanner-official' ),
        'add_new'            => _x( 'Dodaj promocję', 'promocja', 'missplanner-official' ),
        'add_new_item'       => __( 'Dodaj promocję', 'missplanner-official' ),
        'new_item'           => __( 'Nowa promocja', 'missplanner-official' ),
        'edit_item'          => __( 'Edytuj promocję', 'missplanner-official' ),
        'view_item'          => __( 'Zobacz promocję', 'missplanner-official' ),
        'all_items'          => __( 'Zobacz wszystkie promocje', 'missplanner-official' ),
        'search_items'       => __( 'Szukaj...', 'missplanner-official' ),
        'parent_item_colon'  => __( 'Elementy rodzice:', 'missplanner-official' ),
        'not_found'          => __( 'Nie znaleziono.', 'missplanner-official' ),
        'not_found_in_trash' => __( 'Nie znaleziono w koszu.', 'missplanner-official' )
    );

    /**
    * Other options
    **/
    $custom_post_args = array(
        'labels' => $custom_post_labels,
        'description'        => __( 'Wszystkie promocje Miss Planner.', 'missplanner-official' ),
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'promocja' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt' )
    );
    register_post_type( 'promocja', $custom_post_args);

}

add_action( 'init', 'missplanner_promotion_post_type' );

/**
*
* Custom Taxonomy for post type "Promocja"
*
**/
add_action( 'init', 'missplanner_promotion_taxonomy', 0);

function missplanner_promotion_taxonomy() {

    /**
    * custom taxonomy labels
    **/
    $kategorie_promocje_labels = array(
        'name'              => _x( 'Kategorie Promocji', 'taxonomy general name', 'missplanner-official' ),
        'singular_name'     => _x( 'Kategoria Promocji', 'taxonomy singular name', 'missplanner-official' ),
        'search_items'      => __( 'Szukaj kategorii promocji', 'missplanner-official' ),
        'all_items'         => __( 'Wszystkie kategorie promocji', 'missplanner-official' ),
        'parent_item'       => __( 'Kategorie Promocji rodzic', 'missplanner-official' ),
        'parent_item_colon' => __( 'Kategorie Promocji rodzic:', 'missplanner-official' ),
        'edit_item'         => __( 'Edytuj kategorię promocji', 'missplanner-official' ),
        'update_item'       => __( 'Aktualizuj kategorię promocji', 'missplanner-official' ),
        'add_new_item'      => __( 'Dodaj nową kategorię promocji', 'missplanner-official' ),
        'new_item_name'     => __( 'Nazwa nowej kategorii promocji', 'missplanner-official' ),
        'menu_name'         => __( 'Kategorie Promocji', 'missplanner-official' ),
    );

    /**
    * custom taxonomy args
    **/
    $kategorie_promocje_args = array(
        'hierarchical'      => true,
        'labels'            => $kategorie_promocje_labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'promocje' ),
    );

    /**
    * Add taxonomy "Kategorie Promocji"
    **/
    register_taxonomy( 'kategorie-promocji', array( 'promocja' ), $kategorie_promocje_args );

}

And here is the breadcrumb on single product page (everywhere else it works just fine):

After setting all my custom posts as drafts, it goes back to normal. Where should I change my code?

I'm working on a custom theme with some additional features for my store. To gather all promotions in one place in my store back-end and front-end, I created custom post type, custom taxonomy for it. The code for it is:

/**
*
* Registering custom post type 'promocja'
*
**/
function missplanner_promotion_post_type() {

    /**
    * UI Labels
    **/
    $custom_post_labels = array(
        'name'               => _x( 'Promocje', 'post type general name', 'missplanner-official' ),
        'singular_name'      => _x( 'Promocje', 'post type singular name', 'missplanner-official' ),
        'menu_name'          => _x( 'Promocje', 'admin menu', 'missplanner-official' ),
        'name_admin_bar'     => _x( 'Dodaj promocję', 'add new on admin bar', 'missplanner-official' ),
        'add_new'            => _x( 'Dodaj promocję', 'promocja', 'missplanner-official' ),
        'add_new_item'       => __( 'Dodaj promocję', 'missplanner-official' ),
        'new_item'           => __( 'Nowa promocja', 'missplanner-official' ),
        'edit_item'          => __( 'Edytuj promocję', 'missplanner-official' ),
        'view_item'          => __( 'Zobacz promocję', 'missplanner-official' ),
        'all_items'          => __( 'Zobacz wszystkie promocje', 'missplanner-official' ),
        'search_items'       => __( 'Szukaj...', 'missplanner-official' ),
        'parent_item_colon'  => __( 'Elementy rodzice:', 'missplanner-official' ),
        'not_found'          => __( 'Nie znaleziono.', 'missplanner-official' ),
        'not_found_in_trash' => __( 'Nie znaleziono w koszu.', 'missplanner-official' )
    );

    /**
    * Other options
    **/
    $custom_post_args = array(
        'labels' => $custom_post_labels,
        'description'        => __( 'Wszystkie promocje Miss Planner.', 'missplanner-official' ),
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'promocja' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt' )
    );
    register_post_type( 'promocja', $custom_post_args);

}

add_action( 'init', 'missplanner_promotion_post_type' );

/**
*
* Custom Taxonomy for post type "Promocja"
*
**/
add_action( 'init', 'missplanner_promotion_taxonomy', 0);

function missplanner_promotion_taxonomy() {

    /**
    * custom taxonomy labels
    **/
    $kategorie_promocje_labels = array(
        'name'              => _x( 'Kategorie Promocji', 'taxonomy general name', 'missplanner-official' ),
        'singular_name'     => _x( 'Kategoria Promocji', 'taxonomy singular name', 'missplanner-official' ),
        'search_items'      => __( 'Szukaj kategorii promocji', 'missplanner-official' ),
        'all_items'         => __( 'Wszystkie kategorie promocji', 'missplanner-official' ),
        'parent_item'       => __( 'Kategorie Promocji rodzic', 'missplanner-official' ),
        'parent_item_colon' => __( 'Kategorie Promocji rodzic:', 'missplanner-official' ),
        'edit_item'         => __( 'Edytuj kategorię promocji', 'missplanner-official' ),
        'update_item'       => __( 'Aktualizuj kategorię promocji', 'missplanner-official' ),
        'add_new_item'      => __( 'Dodaj nową kategorię promocji', 'missplanner-official' ),
        'new_item_name'     => __( 'Nazwa nowej kategorii promocji', 'missplanner-official' ),
        'menu_name'         => __( 'Kategorie Promocji', 'missplanner-official' ),
    );

    /**
    * custom taxonomy args
    **/
    $kategorie_promocje_args = array(
        'hierarchical'      => true,
        'labels'            => $kategorie_promocje_labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'promocje' ),
    );

    /**
    * Add taxonomy "Kategorie Promocji"
    **/
    register_taxonomy( 'kategorie-promocji', array( 'promocja' ), $kategorie_promocje_args );

}

And here is the breadcrumb on single product page (everywhere else it works just fine):

After setting all my custom posts as drafts, it goes back to normal. Where should I change my code?

Share Improve this question asked Jul 5, 2017 at 9:23 Maciej RogoszMaciej Rogosz 262 bronze badges 1
  • Maybe you forgot to reset post data in the loop <?php endwhile; wp_reset_postdata(); ?> – Morten Andersen Commented Sep 1, 2017 at 10:49
Add a comment  | 

1 Answer 1

Reset to default 0

The solution is quite simple. I copied single-product.php from woocommerce/templates and modified it so loop starts before before_main_content hook:

get_header( 'shop' ); ?>
    <?php while ( have_posts() ) : the_post(); ?>
    <?php   
        /**
        * woocommerce_before_main_content hook.
        *
         * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
         * @hooked woocommerce_breadcrumb - 20
         */
        do_action( 'woocommerce_before_main_content' );
    ?>

That way it works fine, all functionalities are maintained.

Post a comment

comment list (0)

  1. No comments so far