I’m trying to execute some PHP code that is using the WooCommerce variable to get the order ID.

function lolcats()
{

$order = new WC_Order($post_id);

?>
    <script type="text/javascript" >
    jQuery(document).ready(function($)
    {
        $(".alert-mass").click(function(e)
        {
            e.preventDefault();
            alert('<?php echo $order->get_order_number; ?>');
        });
    });
    </script>
<?php
}

I can’t seem to get it to return anything besides either null or 0.

Using something like this obviously works perfectly: window.location="dhlgen.php?order=1234"; because I’m trying to pass it through the URL to a PHP function which uses it later.

Thank you.

Read more here: Javascript – How to pull a WooCommerce variable in PHP?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: