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”?
- 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]
- How do I redirect to another webpage?
- Uncaught SyntaxError: Invalid or unexpected token
- SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
- Trying to load jquery into tampermonkey script
- How to correctly add Javascript in functions.php
- Dynamically update post title in admin page
- WooCommerce add_to_cart() with custom price [closed]
- WooCommerce HTML after short description if product is in specific category
- How to get total count for each star rating?
- WooCommerce Apply Coupon to order AFTER taxes
- Ajax return code 400
- why featured product not updated in postmeta table in woocommerce?
- Add custom setting that uses radio button to WP Gallery
- No data received
- WooCommerce limited role
- Skip WooCommerce 4.5.x onboarding with WP-CLI [closed]
- CodeMirror on Custom Widget Textarea
- How to add existing categories into a post using wp_insert_post
- How to search using ajax for exact phrase or words in an input field?
- create comment box in woo-commerce shop order [closed]
- Woocommerce: how to know if the customer is canceled the order or the shop owner? [closed]
- Access Customizer widget instance form
- My jQuery is enqueued properly. So why isn’t it working?
- How to replace WooCommerce Product Gallery Trigger icon using PHP/CSS? [closed]
- How to show the urls inside the simple product when the customer buys it?
- Custom template – query issues
- Getting in an exception for get product detail by id in woocommerce REST api
- How to save a Woocomerce metabox input as a metadata field
- populating extra field with woocommerce categories
- Woocommerce Shop Manager Capabilities
- How to skip woocommerce checkout after payment page? [closed]
- Product thumbnail size in catalog
- how can i import the csv file in wordpress woocommerce.?
- some products free and some product is not free for shipping
- Conditional email recipient based off Shipping Method [closed]
- Save Woocomerce discount as percentage to database
- jQuery doesn’t work in my php snippet
- WordPress video end function [duplicate]
- Javascript will not run properly
- Use one javascript variable into another javascript file
- Custom product loop avoiding duplicates
- How do I output user_registered time in my correct timezone?
- Ajax in Plugins: returns the whole page
- Woocommerce – Remove ‘Buy Product’ Button + Make Product Thumbnails Clickable
- Making product image in woocommerce invoice linkable [closed]
- Send data to external websites when there is an update or create a post
- Add a custom code with custom link after add to cart for every product
- WooCommerce product permalink based on product’s current category
- Disable duplicate WC product category URLs
- how should i get products based on tags in woocommerce