• Resolved apg1912

    (@apg1912)


    I’m looking through the php code for woocommerce in the ‘templates’ and ‘includes’ folders because I’m looking for how to influence the shipping methods displayed on the checkout page.

    My question is, what is the normal procedure people use to display the contents of a variable, if the name itself doesn’t make this clear.

    For example, if I want to look at $product_names, do I just insert the followed code into the file, temporarily, and run it, or is there a more elegant way of doing it?

    var_dump($product_names);
    die;

    • This topic was modified 4 years, 1 month ago by apg1912.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter apg1912

    (@apg1912)

    I’ve just watched a course on lynda.com where print_f() is suggested for determining what values variables hold. Does this seem a reasonably acceptable way of doing this when doing development? Being new to php programming I’m just trying to establish best practices.

    Hi @apg1912,

    Welcome to PHP programming first of all. Most of the time when working with template files, you can use the same WordPress functions as posts to display titles.

    To display the product’s name in a template file, often you can use this:

    
    <?php the_title(); ?>
    

    If outside of a template, then there are other methods that may be more appropriate. This Stack Overflow answer can give you a few more options.

    https://stackoverflow.com/a/63280622

    I hope that gets you pointed in the right direction.

    Thread Starter apg1912

    (@apg1912)

    Thanks fort the reply, but I am thinking specific internal PHP variables that are only used to temporarily hold data in the code. They are not available at the time the page is displayed. I want to check the contents of them so I can then manipulate them in the PHP code.

    Were you able to read through the StackOverflow answer?

    https://stackoverflow.com/questions/26167916/get-the-product-name-in-woocommerce/63280622#63280622

    It shows multiple ways of getting the title that can be used outside of a template file.

    You can also use var_dump() to show the content in a variable:

    https://www.php.net/manual/en/function.var-dump.php

    Hi @apg1912,

    I hope you were able to get started diving into PHP with WordPress/WooCommerce. It’s been a while since we last heard back from you so I’m going to close out this thread now. If you have any questions, please feel free to open up a new thread and we’ll be happy to jump back in and help.

    Cheers

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Displaying WooCommerce Variables – How Too?’ is closed to new replies.