Editing product meta from single product page

#185782
  • Resolved Fahim Foysal
    Rank Math free

    I followed this guide for rankmath to utilise the ‘Single Product Description’ from rankmath> Titles and meta> product> single product description instead of the default values. I have used this line of code to get it done


    add_action( 'rank_math/frontend/description', function( $generated ) {
    if ( ! is_product() ) {
    return $generated;
    }

    global $post;
    $desc = RankMath\Helper::get_settings( "titles.pt_product_description" );
    $desc = RankMath\Helper::replace_vars( $desc, $post );
    return empty( $desc ) ? $generated : $desc;
    });

    This was taken from https://support.rankmath.com/ticket/use-product-description-meta-from-settings-instead-of-excerpt/

    I want to display the price , woocommerce product long description and woocommerce product short description in that order. I just need to know what the variable is for displaying the long product description of woocommerce.

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for the delay.

    You can create a custom variable for the full product description by adding the code given below to your theme’s/child theme’s functions.php file

    add_action( 'rank_math/vars/register_extra_replacements', function() {
    	rank_math_register_var_replacement(
    		'woo_full_desc',
    		[
    			'name'        => esc_html__( 'Woo Full Desc.', 'rank-math' ),
    			'description' => esc_html__( 'Woo Full Description...', 'rank-math' ),
    			'variable'    => 'woo_full_desc',
    			'example'     => woo_full_desc_callback(),
    		],
    		'woo_full_desc_callback'
    	);
    } );
    function woo_full_desc_callback() {
    	global $post;
    	if ( empty( $post ) ) {
    		return 'Product Description';
    	}
    
    	return wp_strip_all_tags( $post->post_content );
    }

    After this add %woo_full_desc% in the SEO description field of the snippet editor

    You can also use the variable in the global product description since you mentioned that you are forcing the use of it instead of the individual description. Here’s the order you can put:

    %wc_price% - %woo_full_desc% - %excerpt%

    I hope that helps. Thank you, and looking forward to your update.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 1 replies (of 1 total)

The ticket ‘Editing product meta from single product page’ is closed to new replies.