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;
}