[resolved] Inserting the_title() into a function? (5 posts)

  1. apa@imagix.dk
    Posted 7 years ago #


    I want to automaticly insert the current post title into this line where it says PRODUCT-NAME... (in single.php)

    <?php echo print_wp_cart_button_for_product(’PRODUCT-NAME’, PRODUCT-PRICE); ?>

    It's probably simple but i am no good with php.

    Hope somebody can help me?


  2. MichaelH
    Posted 7 years ago #

    Should be able to replace 'PRODUCT-NAME' with $post->post_title as long as that code is in a post loop.

  3. apa@imagix.dk
    Posted 7 years ago #

    It works. Thanks! You dont want to know how much time i spent trying to figure it out by myself!

  4. syncbox
    Posted 6 years ago #

    This is a variation on that question, but definitely related... in the same cart plugin, how could you get the data from a custom field that contains the product name and price into the cart button template code? For example, the cart uses:

    <?php echo print_wp_cart_button_for_product('PRODUCT-NAME', PRODUCT-PRICE); ?>

    and the info I want is stored in custom field keys "MMTname" and "MMTprice".... I am already displaying this data (and more) from custom fields in the same page.

    Help greatly appreciated!

  5. syncbox
    Posted 6 years ago #

    Nevermind... going on what was suggested above, I put the custom field data into $vars like:

    $prodname = c2c_get_custom('MMTname');
    $prodprice = c2c_get_custom('MMTprice');

    and then later, when calling the cart button, used them, like so:

    <?php echo print_wp_cart_button_for_product($prodname, $prodprice); ?>

    Thanks for pointing me in the right direction!

Topic Closed

This topic has been closed to new replies.

About this Topic