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
- Woocomerce custom add to cart button edit functionality [closed]
- Capture the Selected Radio Button Value between two files in wordpress theme
- How to change product SKU’s in bulk with a plugin
- How to change product title color in shop page if product has specific product tag (Woocommerce)?
- Woocommerce Payment Method Change
- How to capture number input from wordpress form into acf field in woocommerce
- Add More Featured Data Not Sending to Database
- Wrap First Character after in a tag
- Making Quote Plugin more efficient
- How to access function from outside of a class within this class in WP plugin?
- Hiding WordPress Plugin Source Code
- How to trash multiple post/product programmatically
- Writing scripts using WordPress / WooCommerce classes?
- How can i display post loop in table format?
- My Own layout in WooCommerce pages [closed]
- How to get woocommerce cart content without an action?
- Order properties should not be accessed directly
- Page Reloads Before AJAX Request Finishes
- WooCommerce: Add Payment Gateway Field to Webhooks [closed]
- Woocommerce – remove product from category
- action hook wp_head higher priority as all other plugins/hooks
- How to create and work with custom data / tables (i.e., for arbitrary data)?
- How do I implement a .diff changeset from core.trac.wordpress.org locally?
- How do I use the Simple HTML DOM Parser in plugin when other plugin already uses it?
- How to make custom total price reactive in navigation
- Query String being Removed Creating a Pagination Issue within a Custom Plugin
- Inject PHP code into “sidebar-content” – code before my WooCommerce sidebar widget?
- Get rewrite slug of custom post type in template
- How to get 2 or multiple custom post types in wordpress functions.php
- OrderItem get_total() returns lower value than $order_item->get_product()->get_price() * quantity
- Add htaccess rules with insert_with_markers at beginning of htaccess
- custom shortcode will not display the wrapped content
- Change description on specific WooCommerce product status change
- Add the Name of Products Ordered to Admin New Order Email WooCommerce
- Changing Woocommerce flat rate every nth number of items
- How to call function at the bottom of post using plugin?
- How to prevent those PHP variables from being cached on WordPress?
- Woocommerce product download URL
- Multiple choice in a custom taxonomy
- How to select WooCommerce products by post_meta and order them
- How to restrict wp generate attachment metadata() to certain intermediate image sizes
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- Setting All Drafts to ‘exclude-from-catalog’ in WooCommerce
- Woocommerce – Filter Variable Products by Variation Attributes and Variations Regular Price
- Insert array data on plugin activation
- Will simple function names in a class structure conflict with other plugins?
- woocommerce – hide payment method in new order email
- Do my defines need to be unique?
- Displaying theme options in css
- WordPress php filter admin_body_class not working