Add custom description to woocommerce shop-site based on IDs

Viewed 228

I would like to add a custom description to my woocommerce shop. I would like to show a different description on the shop and the description (when click on the product) would remain as it was written on the shop.

And I would like to separate it. The only way i see it, it's by using some custom html with php but I have no idea. CSS didn't seem to help. Since I have various products, I'd like to separate it differently by product ID and write the description myself for each of them in order to make it look like:

This is my file oceanwp-strings.php:

<?php
/**
 * OceanWP theme strings
 *
 * @package OceanWP WordPress theme
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

if ( ! function_exists( 'oceanwp_theme_strings' ) ) {

    /**
     * OceanWP Theme Strings
     *
     *  @author Amit Singh (apprimit@gmail.com)
     *  @since 1.8.5
     *
     * @param  string  $value  String key.
     * @param  boolean $echo   Print string.
     * @return mixed           Return string or nothing.
     */
    function oceanwp_theme_strings( $value, $echo = true ) {

        $oceanwp_strings = apply_filters(
            'oceanwp_theme_strings',
            array(

                'owp-string-header-skip-link'            => apply_filters( 'ocean_header_skip_link', __( 'Skip to content', 'oceanwp' ) ),
                'owp-string-search-text'                 => apply_filters( 'ocean_search_text', __( 'Search', 'oceanwp' ) ),
                'owp-string-mobile-search-text'          => apply_filters( 'ocean_mobile_search_text', __( 'Search', 'oceanwp' ) ),
                'owp-string-mobile-fs-search-text'       => apply_filters( 'ocean_mobile_fs_search_text', __( 'Type your search', 'oceanwp' ) ),
                'owp-string-header-replace-search-text'  => apply_filters( 'ocean_header_replace_search_text', __( 'Type then hit enter to search...', 'oceanwp' ) ),
                'owp-string-search-overlay-search-text'  => apply_filters( 'ocean_search_overlay_search_text', __( 'Type then hit enter to search', 'oceanwp' ) ),
                'owp-string-vertical-header-search-text' => apply_filters( 'ocean_vertical_header_search_text', __( 'Search...', 'oceanwp' ) ),
                'owp-string-medium-header-search-text'   => apply_filters( 'ocean_medium_header_search_text', __( 'Search...', 'oceanwp' ) ),
                'owp-string-comment-logout-text'         => apply_filters( 'ocean_comment_logout_text', __( 'Log out of this account', 'oceanwp' ) ),
                'owp-string-comment-placeholder'         => apply_filters( 'ocean_comment_placeholder', __( 'Your comment here...', 'oceanwp' ) ),
                'owp-string-comment-profile-edit'        => apply_filters( 'ocean_comment_profile_edit', __( 'Click to edit your profile', 'oceanwp' ) ),
                'owp-string-comment-post-button'         => apply_filters( 'ocean_comment_post_button', __( 'Post Comment', 'oceanwp' ) ),
                'owp-string-comment-name-req'            => apply_filters( 'ocean_comment_name_req', __( 'Name (required)', 'oceanwp' ) ),
                'owp-string-comment-email-req'           => apply_filters( 'ocean_comment_email_req', __( 'Email (required)', 'oceanwp' ) ),
                'owp-string-comment-name'                => apply_filters( 'ocean_comment_name', __( 'Name', 'oceanwp' ) ),
                'owp-string-comment-email'               => apply_filters( 'ocean_comment_email', __( 'Email', 'oceanwp' ) ),
                'owp-string-comment-website'             => apply_filters( 'ocean_comment_website', __( 'Website', 'oceanwp' ) ),
                'owp-string-search-continue-reading'     => apply_filters( 'ocean_search_continue_reading', __( 'Continue Reading', 'oceanwp' ) ),
                'owp-string-post-continue-reading'       => apply_filters( 'ocean_post_continue_reading', __( 'Continue Reading', 'oceanwp' ) ),
                'owp-string-single-related-posts'        => apply_filters( 'ocean_single_related_posts', __( 'You Might Also Like', 'oceanwp' ) ),
                'owp-string-single-next-post'            => apply_filters( 'ocean_single_next_post', __( 'Next Post', 'oceanwp' ) ),
                'owp-string-single-prev-post'            => apply_filters( 'ocean_single_prev_post', __( 'Previous Post', 'oceanwp' ) ),
                'owp-string-single-screen-reader-rm'     => apply_filters( 'ocean_single_screen_reader_rm', __( 'Read more articles', 'oceanwp' ) ),

                // Woocommerce.
                'owp-string-woo-quick-view-text'         => apply_filters( 'ocean_woo_quick_view_text', __( 'Quick View', 'oceanwp' ) ),
                'owp-string-woo-quick-view-close'        => apply_filters( 'ocean_woo_quick_view_close', __( 'Close quick preview', 'oceanwp' ) ),
                'owp-string-woo-floating-bar-select-btn' => apply_filters( 'ocean_woo_floating_bar_select_btn', __( 'Select Options', 'oceanwp' ) ),
                'owp-string-woo-floating-bar-selected'   => apply_filters( 'ocean_woo_floating_bar_selected', __( 'Selected:', 'oceanwp' ) ),
                'owp-string-woo-floating-bar-out-stock'  => apply_filters( 'ocean_woo_floating_bar_out_stock', __( 'Out of stock', 'oceanwp' ) ),
            )
        );

        if ( is_rtl() ) {
            // do your stuff.
        }

        $owp_string = isset( $oceanwp_strings[ $value ] ) ? $oceanwp_strings[ $value ] : '';

        /**
         * Print or return strings
         */
        if ( $echo ) {
            echo $owp_string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        } else {
            return $owp_string;
        }
    }
}
1 Answers

What you call description is actually the_excerpt();. It's pretty much a short version of your post content. You can learn more about it here @ https://developer.wordpress.org/reference/functions/the_excerpt/ and here https://developer.wordpress.org/reference/functions/get_the_excerpt/

Now that confusion is out of the way, as each themeam is different, you probably have somewhere in your theme file a template part for your products. i'm gonna need the file's code to go further.

Edit your post with the product template part code and I will take a look.


EDIT 1.2: BEFORE DOING ANYTHING SAVE A COPY OF THE PRODUCT TEMPLATE IN A SAFE PLACE

if ( ! $length ) {
   echo wp_kses_post( strip_shortcodes( $post->post_excerpt ) );
} else {
   echo wp_trim_words( strip_shortcodes( $post->post_excerpt ), $length );
}

this is used to fetch the excerpt from the database $post->post_excerpt. No formating is associated with it.

We're gonna use get_the_excerpt() as the formating is passed on.
Source @ https://developer.wordpress.org/reference/functions/get_the_excerpt/

if ( ! $length ) {
   echo strip_shortcodes( 'EDIT 1.2:'.get_the_excerpt() );
} else {
   echo wp_trim_words( strip_shortcodes( 'EDIT 1.2:'.get_the_excerpt()  ), $length );
}
Related