Jump to content

Recommended Posts

Hello i would like to display two titles in product category. For example:

Shop

New Shop Title

Here is my code but it displaying only the alternative title not the Name Title

Any suggestions

 


add_action( 'product_cat_add_form_fields', 'bbloomer_add_category_alt_name' );

add_action( 'product_cat_edit_form_fields', 'bbloomer_edit_category_alt_name' );
 
function bbloomer_add_category_alt_name() {
  echo '<div class="form-field">';
  echo '<label for="ctitle">Alternative title</label>';
  echo '<input type="text" id="ctitle" name="ctitle">';
  echo '</div>';
}

function bbloomer_edit_category_alt_name( $term ) {
  echo '<tr class="form-field">';
  echo '<th for="ctitle">Alternative title</th>';
  echo '<td><input type="text" id="ctitle" name="ctitle" value="' . get_term_meta( $term->term_id, 'ctitle', true ) . '"></td>';
  echo '</tr>';
}


add_action( 'edit_term', 'bbloomer_save_category_alt_title', 10, 3 );


add_action( 'created_term', 'bbloomer_save_category_alt_title', 10, 3 );
 
function bbloomer_save_category_alt_title( $term_id, $tt_id = '', $taxonomy = '' ) {
  if ( 'product_cat' !== $taxonomy ) return;
  if ( isset( $_POST['ctitle'] ) ) {
     update_term_meta( $term_id, 'ctitle', $_POST['ctitle'] );
  } else {
     update_term_meta( $term_id, 'ctitle', '' );
  }
}

add_filter( 'woocommerce_page_title', 'bbloomer_edit_cat_page_title' );
 
function bbloomer_edit_cat_page_title( $title ) {
  if ( is_product_category() ) {
     $term = get_queried_object();
     $title = get_term_meta( $term->term_id, 'ctitle', true ) ? get_term_meta( $term->term_id, 'ctitle', true ) : $title;
  }
  return $title;
    
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.