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
- Update a server-side render Block when woocommerce cart block changed
- How to detect changes in WooCommerce store (react)?
- Issues with WooCommerce: jquery.blockUI.min.js
- jQuery animate backgroundColor
- How to convert selected HTML to Json?
- How to turn off WooCommerce user registration and manually create accounts?
- WooCommerce Change Product Global Attribute Value via CRUD for Simple Product [closed]
- Change WooCommerce Image Size in One Product CAtegory
- Add javascript to a woocommerce page template
- Woocommerce Shop Price Position
- Importing Woocommerce products with variations
- Woocommerce login not working on the first try
- Show add to cart button on shop woocommerce
- How do I hide the purchase note in the WooCommerce ‘order completed’ email?
- Woocommerce – Override the default templates location under the theme directory
- How to hide out of stock products in Related Products via custom query in WooCommerce
- WOO-Commerce translation | Tried it all [closed]
- Change upload folder for a CPT
- Function to recalculate shipping costs on subscriptions after renewal with Automatewoo
- Creating a multisite registration form that also creates a woocommerce post
- How to show tag count for individual product post in wordpress woocommerce
- Add custom field to Woocommerce add new attribute / edit page
- woocommerce axios react
- Woocommerce – Add HTML around Product description [closed]
- relocate woocommerce notices/messages on Cart page
- WooCommerce 4: Gallery size is too large in mobile
- Required radio button does not validate in form, when clicked through Javascript/jQuery
- Woocommerce Remove Tax by Product Type
- get_posts $args won’t accept array as one of the criteria?
- Replacing WordPress Icons (menu,icons32, etc)?
- Woocommerce: How to change the attribute values per product
- WordPress | Woocommerce | use “category display type” in if statement
- Update / refresh mini cart, after custom AJAX add_to_cart event
- How can I get a get a list of customers from a list of email addresses?
- Change the version of default style.css in wordpress
- Remove filter parameter from Link URL
- Awesome Support Custom Field for show Woocommerce orders
- Site with WooCommerce section moved to HTTPS – all pages except home and main store are 404s
- Multiple quantities with options
- Woocommerce make appear when items added to cart
- Carousel Hover Image
- registration_errors not working
- Translate Woocommerce tab
- Woocommerce -> gallery images per variation without a plugin? [closed]
- jQuery Snippet Not Working on WordPress Site [closed]
- Why is my WordPress admin not working
- Woocommerce deleted and replaced my WordPress front/page. How do I restore my original page?