Pat
Pat

Reputation: 727

Add wordpress url in href of js script

I've got code:

if ($('.header').width() < 767 ){
  $(".header__search").html('<a href="/cart" class="d-block xxxd"><img src="/wp-content/themes/img/cart.png" width="16px" /><span class="badge badge-warning" id="lblCartCount">'+$('#barba-wrapper > div > header > div.header__main > div > div.header__user > ul > li:nth-child(2) > a > span').text()+'</span></a>');
});

I need to replace url in href /cart to default wordpress :

<?php echo wc_get_cart_url() ?>

How to put it?

Upvotes: 1

Views: 404

Answers (1)

This will work if you put the code in the PHP template file or functions.php.

Example for functions.php:

add_action( 'wp_footer', 'wp_footer_javascript', 99 );
function wp_footer_javascript(){
?>
<script> 
if ($('.header').width() < 767 ){
    $(".header__search").html('<a href="<?php echo wc_get_cart_url() ?>" ...');
});
</script>
<?php
}

Upvotes: 2

Related Questions