1

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?

0

1 Answer 1

2

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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.