Update 2020
Answer
See flytech’s answer for a solution using the native WooCommerce API.
Note / Caveat
If you’re going to do proper arithmetic with monetary values, always use signed integers (!) representing the smallest denomination of a given currency (Cent, Penny, Paisa, Dirham, e.g.).
Only convert back to decimal fractions in the presentation layer of your application after all calculations are done.
This holds true regardless of language or framework.
Original answer
I don’t know woocommerce at all and hence there might be a native way as well, but anyhow, this
$amount = floatval( preg_replace( '#[^\d.]#', '', $woocommerce->cart->get_cart_total() ) );
should do.
The preg_replace
eliminates everything but decimal characters and colons.
Should you care to do math with it, the floatval
converts the value from a string to a numeric one.
Related Posts:
- Markdown in WordPress 3.2?
- Store post in raw markdown format, no html?
- Can’t create term for product attribute
- Limit Number of Taxonomy Terms (Images) Displayed
- Want wp_get_post_terms return in arbitrarily order, how to do?
- List taxonomy terms for post as checkboxes
- Generate pages from markdown files in github automatically
- How to Display Taxonomy Custom Meta Box Data in Archive Page?
- Why Is This Code Causing The Admin Bar to Disappear?
- Ordering taxonomies by rank
- Checking if a woocommerce attribute is set
- Getting taxonomy images to display on single-post with their terms
- Where to populate custom terms in custom taxonomy in plugin?
- How to display terms and conditions in post area?
- wp_insert_term() doesnt insert a term
- Exporting Custom Taxonomy in plugin
- Smarter navigation plugin and custom taxonomies
- Only return taxonomies that are linked to a category & product
- Why is my custom taxonomy image not displaying?
- Get only selected custom taxonomy
- Get custom term link archive with prefix
- Add “selected” class to custom taxonomy dropdown search
- Can’t pull metadata for a term in my theme’s function.php
- Find And Add Category to Posts
- How MUST the directory for a plugin be structured?
- Is there a WordPress plugin that registers a plugin file as a custom page template?
- Is there a good plugin for an online booking system..? [closed]
- Automating deprecated call checks?
- How can I make my custom shortcode work in a Custom HTML Widget?
- post_id always wrong in plugin
- Should we use plugins that aren’t available from the official WordPress site?
- Adding a form at the end of the content
- Ajax call doesn’t work in frontend but it’s working in backend (when I’m logged in)
- Creating a wordpress plugin where users can override templates
- How to use static flattr buttons
- Taking WordPress table prefixes into account
- Changing BIGINT to INT
- Can I run multiple queries with $wpdb->prepare?
- Get Plugin Information from Multiple Sites Externally
- add_filter the_content in functions.php not working
- javascript onload calling a function of a plugin
- Multisite Widget/Content
- May i Use ShortCode in Template?
- plugin ajax to external php file always return null
- Best way to modify a plugin with no hooks and no pluggable functions?
- Auto delete WordPress users according to time
- How to cancel WordPress’ action/filter when using OOP with anonymous callback
- How to stop xmlrpc attacks without disabling component to allow JetPack to work in WordPress?
- Multiple sites, multiple countries
- Do action only on certain front end pages?
- Theme my Login plugin, how to update fields
- How to resolve error after installing plugin? [closed]
- Create a navbar filter that filters by a custom field
- Advanced Custom Field DatePicker [closed]
- Polylang : Interverting languages after development [closed]
- Lock access to plugin options
- How to set Noindex to all wordpress pages in a catergory?
- How to get post ID with hooks publish_post, new_to_publish, etc
- Admin AJAX doesn’t work in plugin admin page – Even though code is copied verbatim from WordPress Codex
- Prevent plugin from intruding on wp-json posts api
- How do i get file_get_contents to work in wordpress
- Plugin Development – Functions or Hooks?
- What happens when WordPress memory limit is exceeded?
- Making that Admin Bar transparent or a blue color
- Use wp_upload_dir() correctly
- Looking for a free quiz plugin which saves the candidates answers for review [closed]
- Allowing .rfa Files In Media Upload [duplicate]
- Some WordPress Posts are automatically becoming comments on other Posts
- WordPress: Add custom add_filter for custom functions
- Best way to duplicate specific page content across two sites?
- How to change layout of shop page in wordpress? [closed]
- If post exists in the database – each time goes on `else`
- Per theme plugins?
- Multiple images per post – Show random image elsewhere
- Edit part of a post
- How to fix these PHP Warnings with the “Feed JSON” plug-in?
- How to Join wp_posts & wp_postmeta table using custom query
- Calling PHP function with AJAX
- Randomize post (and page) IDs on generation
- Cron task gets removed from the schedule
- My wordpress local urls is still displayed even moved to live
- “Enable Media Replace” plugin does not update serialized object in WPMeta
- How to Unhook actions/filters in within Class in plugin
- How to show private pages based on a user’s role?
- My plugin can’t see my files
- Plugin with AJAX on subdomains causes 404 in console
- wordpress disable certain plugins for catagory?
- Create csv file in plugin
- Option page not updating multiple records in settings api
- The plugin generated XXX characters of unexpected output…help?
- Using “Authy Two Factor Authentication” in custom login page
- Managing database tables in WordPress multisite
- Can Shopp Commercial Plugin be hacked to display radio buttons instead of Dropdowns? [closed]
- wp_update_post does not change post status from draft to publish, returns 1
- No way to add instagram in AddToAny Plugin?
- WooCommerce doesn’t show UK countries in the shipping options [closed]
- plugin for different writers [closed]
- Like/Dislike plugin crawler problem
- Post sorting and ordering function in WordPress Admin is broken and always shows post from oldest to newest
- How to edit a non logged in page?