You can pass it to the script via the functions.php file or a plugin using the wp_localize_script function.
<?php
function my_load_scripts() {
wp_enqueue_script('my-script', plugin_dir_url( __FILE__ ) . 'js/my-script.js');
wp_localize_script('my-script', 'my_script_vars', array(
'woo_cart_url' => get_permalink( wc_get_page_id( 'cart' ) )
)
);
}
add_action('wp_enqueue_scripts', 'my_load_scripts');
Then it will be available in your script ( in the example: my_script_vars.woo_cart_url )
https://pippinsplugins.com/use-wp_localize_script-it-is-awesome/
Related Posts:
- Force uppercase on some WooCommerce checkout fields input
- Ajax add to cart not updating Elementor mini cart totals
- Running JavaScript after using WooCommerce Filter Plugin
- Format number to 2 decimal places
- Removing ‘woocommerce-no-js’ class from body
- How do I fix this “Uncaught ReferenceError: woodmartThemeModule is not defined”?
- WooCommerce custom SVG coloring tool [closed]
- List of JS events in the WooCommerce frontend
- Apply jquery script to only woocommerce product pages and categories
- Hide Add to Cart Button
- Change add to cart text if a product is in cart on WooCommerce
- Set a specific default stock quantity on all WooCommerce new products
- How to stop a Gutenberg Block from firing multiple GET Requests?
- How to implement Handling Fee like the Shipping on Cart and Checkout page on WooCommerce [closed]
- How to update the WooCommerce cart Icon to show new products added with JavaScript
- Update html tag class values based on Woocommerce product attribute dropdown selection [closed]
- “Cannot read property ‘replace’ of undefined” Javascript error when trying to add attribute terms from add product page [closed]
- Woocommerce checkout page reload on up dating shipping method
- Javascript / Ajax Error After Migrating To New Domain Name
- How can i stop woocommerce checkout event based on api request result?
- Modifying a .js Function for Print [QZ Tray, WooCommerce POS]
- adding a script with type=”module” to woocommerce admin area
- Woocommerce Moving Review Below add to cart breaks button
- In WooCommerce product archive, how can you also set the quantity to be added to cart by typing, instead of just by using +/-?
- jquery.validation.js is not working in woocommerce checkout page form
- WooCommerce Ajax Cart Update Stopped Working
- jQuery – Automatic event trigger does not **really** check my form
- Javascript error when adding an item to the cart [closed]
- WooCommerce event works in jQuery but not in JavaScript
- Add to cart – button should be disabled
- Using the WordPress and WooCommerce REST APIs in the same Node app
- Auto scroll to id on page load on all pages except home page. Only do this on mobile
- How to Remove Active css from woocommerce variation?
- Woocommerce variable product’s total amount by javascript
- Trying to run Javascript on AJAX call
- List of JS events in the WooCommerce frontend
- Dynamic product total add to cart amount
- Woocommerce Checkout Page Total Price Inside Google Pay Script
- How to add php variable inside wc_enqueue_js(‘jQuery’) function?
- Deregister dequeue JS scripts except on 1 product page
- woocommerce deposit Form with AJAX and shortcode won’t update but add to previous output
- How to make wocommerce shop products same heigt
- Can’t add Select2 to select in variable product (admin)
- AJAX to add to cart multiple products woocommerce
- Woocommerce Flexslider touch functionality on desktop not working
- currentURL is not defined
- How to echo a PHP code into WooCommerce variation product?
- How to insert link, with lightbox, that opens specific page content only
- Notify user we would like them to clear their cookie. Provide a working button to clear cookies for user
- Add specific phrase after every product title including the discounted price? [closed]
- Woocommerce custom product with JS script, can’t understand how it works [closed]
- Loading specific ajax from a product
- Retrive the value of the Active variation of the product and then link it to the “read more” to dynamically change
- How to add icon to WooCommerce add to cart button
- Update a server-side render Block when woocommerce cart block changed
- How to detect changes in WooCommerce store (react)?
- Add JavaScript to all WooCommerce Products
- Adding a Calculator to a WordPress Page
- Changing a text label into an image
- Add shipping address to Woocommerce order emails [closed]
- Adding Buy Button to Blog Post (Woocommerce) [closed]
- How to set a default value in a meta box
- “JQMIGRATE: Migrate is Installed” How do I find the problem code? [duplicate]
- Is it save to use eval for a jQuery callback method coming from the database?
- Referrer URL with jQuery or Javascript – Cache & Referrer URL Issue
- Jquery window.send_to_editor function
- Can I have one picture for all sizes in a product with Woocommerce?
- Woocommerce get the Archive/Category slug of the current category page
- Woocommerce Variable Product – Please choose product options… [closed]
- Why doesn’t jQuery use $, and how can I get it do so (GLOBALLY)?
- Adjust Price Display for Variable Product in Woocommerce [closed]
- woocommerce list product by id
- woocommerce – how to get product link by id
- woocommerce_register_post action not firing [closed]
- wordpress add_action() issue in ajax call
- woo product , wp_insert_post() never displays on the front end. What gives? [closed]
- JQuery Plugins in WordPress
- Create special WordPress slideshow with “jquery.cycle.all.js”
- Using Foundation 5 in WordPress Administration Area
- I have an old version of jQuery showing up. How do I figure out where it is coming from?
- Disabling shopping basket in WooCommerce [closed]
- Results not being printed
- Remove ‘product’ & ‘product-cateogory’ from url – woocommerce [closed]
- Plugin Scripts no loading on options page
- Close Fancybox, sumbit form data and redirect
- How do I include javascript/jquery image resizing with wordpress?
- Localizing methods for jQuery append prepend wrap parent
- Ajax Validation for reCaptcha
- How do I make my wordpress post appear in a mouse hover preview?
- How to enque js script in footer that are not in .js file?
- Using JQuery to check for Rel Attribute of Image before Overriding It
- Loading scripts on a single page plants the script in the footer
- Getting a ‘slide down’ js panel implemented within WP
- Properly embed javascript into WP (using function.php) – doesn’t work?
- Search input area autogrow – how?
- Using jquery and javascript in WordPress
- Nested Gallery Shortcode INTERMITTENTLY working
- How to add drag and drop functionalities to a div inside option panel
- Run a jquery script on on a certain template page
- Woocommerce check if email already created order recently [closed]