0
votes

I am building a wordpress ecommerce template with Cart66 plugin. Using a Cart66 shortcode inside a php template page, I would like to generate the Post ID inside the shortcode. Can someone please help and tell me if this is possible. Here is the code that I am using.

<?php echo do_shortcode("[add_to_cart item=\". the_ID() .\" quantity=\"user:1\"]"); ?>

This code will lay inside loop-single.php and above

Thank you!

3

3 Answers

1
votes

@silent almost had it, but it should be get_the_ID() and not the_ID() since the later one echos it out, so try:

<?php echo do_shortcode("[add_to_cart item=\"". get_the_ID() ."\" quantity=\"user:1\"]"); ?>
0
votes

The right line should be:

<?php echo do_shortcode("[add_to_cart item=\"". the_ID() ."\" quantity=\"user:1\"]"); ?>
0
votes

simpler correct answer:

<?php echo do_shortcode('[add_to_cart item="'. get_the_ID() .'" quantity="user:1"]');?>