N
N
Nik Master2020-05-15 00:49:56
WordPress
Nik Master, 2020-05-15 00:49:56

How to make different templates for woocommerce categories?

It is necessary to display a block with text at the bottom of the page in different categories of goods. Accordingly, for each category the text will be different. How to implement it? Maybe there is a plugin?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nik Master, 2020-05-15
@NikMaster777

Thanks to all. Solved the problem. Solution: paste the code into functions.php and an additional description will appear in each category, which will be displayed at the bottom of the category page.

add_action( 'product_cat_edit_form_fields', 'wpm_taxonomy_edit_meta_field', 10, 2 );
function wpm_taxonomy_edit_meta_field($term) {
$t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$content = $term_meta['custom_term_meta'] ? wp_kses_post( $term_meta['custom_term_meta'] ) : '';
$settings = array( 'textarea_name' => 'term_meta[custom_term_meta]' );
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[custom_term_meta]">Дополнительное описание</label></th>
<td>
<?php wp_editor( $content, 'product_cat_details', $settings ); ?>
</td>
</tr>
<?php
}
add_action( 'edited_product_cat', 'save_taxonomy_custom_meta', 10, 2 );
add_action( 'create_product_cat', 'save_taxonomy_custom_meta', 10, 2 );
function save_taxonomy_custom_meta( $term_id ) {
  if ( isset( $_POST['term_meta'] ) ) {
    $t_id = $term_id;
    $term_meta = get_option( "taxonomy_$t_id" );
    $cat_keys = array_keys( $_POST['term_meta'] );
    foreach ( $cat_keys as $key ) {
      if ( isset ( $_POST['term_meta'][$key] ) ) {
        $term_meta[$key] = wp_kses_post( stripslashes($_POST['term_meta'][$key]) );
      }
    }
    update_option( "taxonomy_$t_id", $term_meta );
  }
}
add_action( 'woocommerce_after_shop_loop', 'wpm_product_cat_archive_add_meta' );
function wpm_product_cat_archive_add_meta() {
  $t_id = get_queried_object()->term_id;
  $term_meta = get_option( "taxonomy_$t_id" );
  $term_meta_content = $term_meta['custom_term_meta'];
  if ( $term_meta_content != '' ) {
    if ( is_tax( array( 'product_cat', 'product_tag' ) ) && 0 === absint( get_query_var( 'paged' ) ) ) {
      echo '<div class="woo-sc-box normal rounded full">';
      echo apply_filters( 'the_content', $term_meta_content );
      echo '</div>';
    }
  }
}

O
Orkhan Hasanli, 2020-05-15
@azerphoenix

I would implement more simply.
All you need to do with ACF is to create a field for adding text and attach it to Woocommerce categories. Further, in the template that displays the categories of the WOOMERTS, display this field and that's it. And you don't have to create a bunch of templates, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question