• I am asking for desperate help after spending at least 4 hours trying to work this out…

    I am using a WordPress/Woocommerce theme which has an Accordion short code.
    I am trying to put the shopping cart variations (preferred product color etc) into the drop down accordion (for info this is due to the huge number of variations my customers may have).

    With help from the WP Codex this seemed simple enough however I just can’t get the code to work (see below). I have successfully tested the accordion and the PHP independently – I just need to merge them together somehow.
    I am new to PHP so please bear with me…

    I have declared the chunk of PHP first (which also contains HTML) and then finally put it into the short code:

    <?php $details = foreach ( $item_data as $data ) :
    			$key = sanitize_text_field( $data['key'] );
    
    		'<dt class="variation-'
    
    echo sanitize_html_class( $key ); '">'
    echo wp_kses_post( $data['key'] ); ':</dt>'
    		'<dd class="variation-'
    echo sanitize_html_class( $key ); '">'
    echo wp_kses_post( wpautop( $data['value'] ) );
    '</dd>'
    endforeach; ?>
    
    <?php echo do_shortcode( '[accordion][accordion-item title="Details"]' . $details . '[/accordion-item][/accordion]' ); ?>

    I would be so grateful if someone could look over it and tell me what I’m doing wrong.
    If you need me to explain further about what I’m trying to do just let me know.
    Cheers : )

Viewing 2 replies - 1 through 2 (of 2 total)
  • Suggest that you ask this question in the Woocommerce support forums, they have the relevant experience there.
    Also read their examples and sample code.

    Also suggest that you use this php syntax checker:
    http://www.piliapp.com/php-syntax-check/
    to check your php code syntax, your home grown code needs sorting out.

    You probably also need these docs on using shortcodes:
    http://codex.wordpress.org/Shortcode_API
    Among other points it is important (and a common mistake we have all made) to use “echo” in shortcode functions, the correct usage is to “return” the text which replaces the shortcode.

    Thread Starter bloomindustries

    (@bloomindustries)

    Ok thanks I’ll check out the Woocommerce forum.
    For info I didn’t write any of the code containing the ‘echo’s. This is just standard woo commerce code that I simply put into the short code.
    Cheers : )

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Accordian PHP Help Needed’ is closed to new replies.