• I guess this is a problem of parsing but couldn’t figure it out after few hours on it. I am close to the solution but stuck and starting to drive me crazy!

    The issue: I can’t get my excerpt (description) dynamically as it looks like my variable $my_id is returning null when I am pushing it into the function get_the_excerpt()

    <?php ob_start(); ?>
        {{ data[ index ].option_id }}
    <?php $my_id = ob_get_clean(); ?>
    
    <?php $product_description = get_the_excerpt($my_id); ?>
    <span class="radio_button_desc"><?php echo apply_filters( 'woocommerce_composited_product_excerpt', wpautop( do_shortcode( wp_kses_post( $product_description ) ) ), $product_id, $component_id, $composite ); ?></span> 
    I have already tried to push the id directly like the following:
    
    <?php $product_description = get_the_excerpt(123456); ?>

    And guess what? It’s working.

    I also tried to parse $my_id to an (int). My gettype() is returning it as an int but my variable return “0” in that case.

    echo $my_id is returning the right numbers (id) so I can’t get why it doesn’t work when I push it through my variable inside get_the_excerpt($my_id);

    I have also tried to trim and updated my code to see the return:

    <?php ob_start(); ?>
        {{ data[ index ].option_id }}
    <?php $my_id = ob_get_clean(); ?>
    <?php var_dump($my_id); ?>
    <?php $product_description = get_the_excerpt( $my_id ); ?>
    <?php print_r(get_the_excerpt( $my_id )); ?> <!-- return nothing */ -->
    <span class="radio_button_desc"><?php echo apply_filters( 'woocommerce_composited_product_excerpt', wpautop( do_shortcode( wp_kses_post( $product_description ) ) ), $product_id, $component_id, $composite ); ?></span>

    OUTPUT:

    Output when I parse it to an integer by adding $my_id = is_int($my_id) ? $my_id : (int) $my_id; :

    This is basically returning me the excerpt of my actual post and not dynamically with the id of $my_id.

    Any clue on it HOW TO RETURN THE OPTION ID from a COMPOSITE product??

    Cheers!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘WC composite product -> get_the_excerpt / Html to php var’ is closed to new replies.