0

I'm trying to replace a whole tag with a shortcode, if the tag text equals a value. I'm placing this script into the footer of the page. Here's what I'm trying:

var stockcounter = document.getElementsByClassName("stock in-stock");

if(stockcounter[0].innerHTML=='0 in stock') {
    //Displays timer
    stockcounter[0].outerHTML = do_shortcode('[fergcorp_cdt_single date="Feb 25 2019 18:45:00"]');
}

This doesn't change the target tag at all. Does anyone know what I'm doing wrong?

0

1 Answer 1

0

This looks like javascript. do_shortcode is a php function. I'm not sure the full context, but at the very least, you need to wrap your php function in php tags like this and add an echo:

<?php // Start of php file ?>
<script>
    var stockcounter = document.getElementsByClassName("stock in-stock");

    if(stockcounter[0].innerHTML=='0 in stock') {
        //Displays timer
        stockcounter[0].outerHTML = "<?php echo do_shortcode('[fergcorp_cdt_single date="Feb 25 2019 18:45:00"]'); ?>";
    }
</script>

I'm assuming this script is within a php file.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.