I’m working on WooCommerce, and I want to replace the Tabs with an accordion. I’m trying to change the menu from Tabs, and I’ve used the shortcode [product_description]
I’m using this PHP code, which displays the product description on my current product details page. However, when I add a new product, the product description changes, and when I go back to the previous product, the description has been updated to match the new product.
How can I fix this?
Thank you
add_shortcode( ‘product_description’, ‘display_product_description’ );
function display_product_description( $atts ){
  $atts = shortcode_atts( array(
    ‘id’ => null, // Default to null, explicitly check for it
  ), $atts, ‘product_description’ );
  $product_id = $atts[‘id’];
  if ( ! $product_id ) {
    // If no ID is provided, try to get it from the current post if it’s a product
    if ( is_product() ) {
      $product_id = get_the_ID();
    } else {
     return ”; // or a message like “Product ID not provided”
    }
  }
  $product = wc_get_product( $product_id );
  if ( ! $product || ! $product->is_visible() ) { // Check if the product exists and is visible
    return ”; // or a message like “Product not found”
  }
  return $product->get_description();
}