Stock status in SEO rank_math/frontend/description

  • Hello, i found usefull function, that replace short_desc if no data entered on frontend with Title – Price currency. – Brand. I want to add stock status between Title and Price, how can i do that? That’s the function, it’s worked fine:

    add_filter( ‘rank_math/frontend/description’, function( $description ) {
    if ( is_singular( ‘product’ ) ) {
    global $post;
    $description = RankMath\Post::get_meta( ‘description’, $post->ID );
    if ( ” !== $description ) {
    return $description;
    }

    $value = RankMath\Helper::get_settings( ‘titles.pt_product_description’ );
    $product = wc_get_product( $post->ID );
    $value = str_replace( ‘%title%’, $product->get_title(), $value );
    $value = str_replace( ‘%wc_shortdesc%’, $product->get_short_description(), $value );
    return ” !== $value ? RankMath\Helper::replace_vars( $value, $product ) : ”;
    }

    return $description;
    });

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math today.

    You can use the following to get the stock quantity:

    
    $product = wc_get_product( $post->ID );
    $stockleft  = $product->get_stock_quantity();
    

    Hope that helps you. Thank you.

    ​​​​​​

    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 ‘Stock status in SEO rank_math/frontend/description’ is closed to new replies.