As I was trying to add some additional amount to my charge and I was unable to update the charge amount. The code which I was trying was this using AJAX call:
$woocommerce->cart->set_total($woocommerce->cart->total + $additional_amount);
But the real problem was with my payment method, not the cart price. So, I resolved it using a filter which happens just before charge amount is about to sent to database and payment gateway.
The code which works for me is this:
function additional_amount($order){
$total_additional_amount = $amount1 + $amount 2;
$total_additional_amount = round($total_additional_amount, 2);
$order->set_total( $total_amount);
}
add_filter( 'woocommerce_checkout_create_order', 'additional_amount', 10, 1 );
Using this filter, I was able to update the actual charge amount.
I hope that will help to someone.
Related Posts:
- Creating custom Woocommerce attribute taxonomies from a plugin
- Display a selected custom product option in WooCommerce cart
- Use wc_enqueue_js only on specific pages – nested add_action
- Authenticating to WordPress, using my own authentication two-factor system
- Add attribute / custom attribute to product in woocommerce
- Why WordPress architecture is not pure object oriented and it don’t use MVC pattern? [closed]
- PHP can I add line numbers to file_get_contents()
- woocommerce subscriptions – get expiration date [closed]
- Automated Cart Update With Alert Box Each Time
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- filter default query to show just selected level of child pages in wordpress
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- Trying to build simple deposit code that hooks into woocommerce
- How to auto fetch customer details in Woocommerce in checkout page
- I want to add custom add to cart link [closed]
- Redirect to another page using contact form 7? [closed]
- How to get private property in parent class into extended class?
- How to obtain the current website URL in my theme?
- What exactly do this function declared into functions.php file of a WP theme?
- Extend Woocommerce Widget Class – WC_Widget_Product_Categories
- Hook called before text widget save
- Change product_base programmatically
- Can a plugin redirect product page based on IF condition?
- Custom Registration username_exists / email_exists
- WordPress WP_Query without query GET parameters
- Where to copy woocommerce files to in my custom theme to avoid editing the core plugin?
- After disabling WPML multi currency, the currency is still handled by the WPML
- custom post type with role Vendor
- How do i wrap woocomerce attribute in list?
- Woocommerce custom Plugin in wordpress [closed]
- Add a custom WooCommerce settings tab with sections
- Payment field disappears on custom Paypal plugin
- I am having errors with checkout on wordpress
- How do I know if the user is a customer?
- product_type_options get saved value [closed]
- I want to fusion the product columns in email table order
- Add a new view on the Woocommerce account page
- How to identify which php file a plugin is using on page load?
- Looping through and combining calls to Woocommerce REST API
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- How to import woocommerce custom fields data into another site?
- How do I remove an action hook inside a class that is called by another class?
- Add custom attribute to product’s HTML to woocommerce cart page
- Autoloading Classes in Plugins
- Woocommerce list variations that are added already to cart in Single Product
- How keep woocommerce users separeted in multisite install and keep admins on network
- Woocommerce linking variations
- Custom field fetch error on woocommerce pdf invoice
- WP Custom tables query
- Woocommerce Convert existing order to the cart
- When to use Exceptions vs Error Objects vs just plain false/null
- WordPress and event-driven programming – what is it about?
- Woocommerce get selected shipping zone id for the current user
- Limit the Excerpt field in WP-Admin in words
- How to show order data by multiple ID?
- how to create and show sessions in word press?
- Problem with Woocommerce REST API Authentication
- How to add SVG icon above product tab title
- How to change / delete product short description in Woocommerce
- How to trash multiple post/product programmatically
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- Random Default Avatar Function
- Custom Text in WooCommerce Order Processing Email Based on Products
- Customizer: Output default value in Customizer CSS
- Converting HTML Template to WordPress Theme
- Saving an array of dynamic repeater data as post_meta
- How can I apply_filters from inside a function?
- Displaying Woocommerce Product Category in WordPress
- Woocommerce : Can’t get product info in loop
- PHP > Scheduled Tasks > Sending daily email with dynamic API variables
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- “Undefined index” error when saving empty array with checkboxes
- How to fix this PHP warning in WP-Admin after upgrading to 3.1.2?
- Scheduling an event inside plugin class is not working
- Where is the PHP code generating an element?
- Basic wpdb update question
- Only show size attributes in product box woocommerce when available
- WordPress widget and customize.php not working in Ubuntu16.04 VPS
- Removing files programmatically
- WooCommerce “Checkout Now” button [closed]
- Create condition for Author bio Social Links
- Is it possible to access admin-ajax.php using PHP?
- Call to “admin_notices” hook from a static method
- Adding custom field to product category and show it to shop/category shop page
- How to hide a div section when user is logged in, in single product woocommerce
- Woocommerce checkout page – custom field checkbox value into email
- Create form which redirects to site in network?
- WooCommerce Quantity in Dropdown menu instead of clasic [closed]
- Custom Plugin Develoment, Form Action
- WordPress Query Crashes Browser
- How to Request a User to Register on Landing at a Site, Then Automatically Delete the Users Password on Logout?
- Plugin Modification Change Functionality For Logged User Only
- Where can I find the declaration of `$_wp_theme_features`?
- WordPress using get_term to retreive slug not working as expected
- add shortcode heading showing multiple time
- Display tab title as ‘blog tagline | blog title’
- Check if values exists DB
- using a shortcode in a hyperlink
- How to change shipping method title based on cart amount?
- Redirect posts to post editor page based on query string