• Resolved babiskalogirou

    (@babiskalogirou)


    Hello dear mates!

    I found this excellent code below, that adds a decription of the product category to the bottom of the relative page:

    /**
    
     * @snippet       Add new textarea to Product Category Pages - WooCommerce
    
     * @how-to        Get CustomizeWoo.com FREE
    
     * @author        Rodolfo Melogli
    
     * @compatible    WooCommerce 5
    
     * @donate $9     https://businessbloomer.com/bloomer-armada/
    
     */ 
    
    // ---------------
    
    // 1. Display field on "Add new product category" admin page
    
    add_action( 'product_cat_add_form_fields', 'bbloomer_wp_editor_add', 10, 2 );
    
    function bbloomer_wp_editor_add() {
    
        ?>
    
        
            <label for="seconddesc"><?php echo __( 'Second Description', 'woocommerce' ); ?></label>       <?php       $settings = array(          'textarea_name' => 'seconddesc',          'quicktags' => array( 'buttons' => 'em,strong,link' ),          'tinymce' => array(             'theme_advanced_buttons1' => 'bold,italic,strikethrough,separator,bullist,numlist,separator,blockquote,separator,justifyleft,justifycenter,justifyright,separator,link,unlink,separator,undo,redo,separator',             'theme_advanced_buttons2' => '',          ),          'editor_css' => '<style>#wp-excerpt-editor-container .wp-editor-area{height:175px; width:100%;}</style>',       );       wp_editor( '', 'seconddesc', $settings );       ?>        

    <?php echo __( 'This is the description that goes BELOW products on the category page', 'woocommerce' ); ?>

       
        <?php } // --------------- // 2. Display field on "Edit product category" admin page add_action( 'product_cat_edit_form_fields', 'bbloomer_wp_editor_edit', 10, 2 ); function bbloomer_wp_editor_edit( $term ) {     $second_desc = htmlspecialchars_decode( get_woocommerce_term_meta( $term->term_id, 'seconddesc', true ) );     ?>     <tr class="form-field">         <th scope="row" valign="top"><label for="second-desc"><?php echo __( 'Second Description', 'woocommerce' ); ?></label></th>         <td>             <?php          $settings = array(             'textarea_name' => 'seconddesc',             'quicktags' => array( 'buttons' => 'em,strong,link' ),             'tinymce' => array(                'theme_advanced_buttons1' => 'bold,italic,strikethrough,separator,bullist,numlist,separator,blockquote,separator,justifyleft,justifycenter,justifyright,separator,link,unlink,separator,undo,redo,separator',                'theme_advanced_buttons2' => '',             ),             'editor_css' => '<style>#wp-excerpt-editor-container .wp-editor-area{height:175px; width:100%;}</style>',          );          wp_editor( $second_desc, 'seconddesc', $settings );          ?>            

    <?php echo __( 'This is the description that goes BELOW products on the category page', 'woocommerce' ); ?>

            </td>     </tr>     <?php } // --------------- // 3. Save field @ admin page add_action( 'edit_term', 'bbloomer_save_wp_editor', 10, 3 ); add_action( 'created_term', 'bbloomer_save_wp_editor', 10, 3 ); function bbloomer_save_wp_editor( $term_id, $tt_id = '', $taxonomy = '' ) {    if ( isset( $_POST['seconddesc'] ) && 'product_cat' === $taxonomy ) {       update_woocommerce_term_meta( $term_id, 'seconddesc', esc_attr( $_POST['seconddesc'] ) );    } } // --------------- // 4. Display field under products @ Product Category pages add_action( 'woocommerce_after_shop_loop', 'bbloomer_display_wp_editor_content', 5 ); function bbloomer_display_wp_editor_content() {    if ( is_product_taxonomy() ) {       $term = get_queried_object();       if ( $term && ! empty( get_woocommerce_term_meta( $term->term_id, 'seconddesc', true ) ) ) {          echo '

    ' . wc_format_content( htmlspecialchars_decode( get_woocommerce_term_meta( $term->term_id, 'seconddesc', true ) ) ) . '

    ';       }    } }

    My question is if there is a way to display the descrption not to the bottom but on the top.

    Thank you in advance!

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter babiskalogirou

    (@babiskalogirou)

    Eventually it was easy, even for a beginner as i am. I just replaced “after” with “before”

    Thank you!

    Hi there @babiskalogirou,

    I’m glad you found this code useful and were able to adjust it for your needs.

    Kindly note, they are accepting donations -details up-top, in the snippet’s comment section.

    I’ll go ahead with marking this thread as resolved now. Feel free to open a new one, should you need anything else. We’re happy to help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Description of product category on top of category page’ is closed to new replies.