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)?
- How to trigger WooCommerce order complete email?
- How to automatically apply woocommerce product title to all product images alt tags?
- How to Use the Function is_user_logged_in To Display Different Menus?
- WooCommerce – Customer Order History Pagination
- String replace WordPress Site Title
- Theme url in all plugin pages
- Display related products with custom output
- Applying OO patterns and principles to plugin development
- WooCommerce – Email admin with new user details
- Auto-update products after they were published – Woocommerce
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- wordpress + woocommerce display product with additional information [closed]
- Customizer: active_callback and sanitize_callback incompatibility?
- Redirect specific user role to specific site after login?
- Send multiple attachments with wp_mail in PHP
- How can I hide that I Use WordPress (with W3 Total Cache)
- Replace Woocommerce “add to cart” to be “Download” button [closed]
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- Custom meta box values are not getting saved for my custom post type
- How to include custom PHP file both in header and footer files
- How to display a custom product field value of a specific category on a Woo Commerce checkout page?
- Personalize checkout text
- Custom Taxonomy Select Menu: Setting default option value?
- Woocommerce Custom Meta Boxes- How to only display if they actually have content
- Display Sibling WooCommerce Product Categories on Archive Page
- Using ACF Relationship field to set post type to draft or published status
- How to update ticket price programatically when adding to cart and checkout in woocommerce
- Woocommerce My acount page
- How can i avoid duplicate same post in wp?
- IF statement not working – Any suggestions?
- get_filtered_term_product_counts – Get product terms if any products
- register_setting not save checkbox
- How does one make a URL return dynamic JSON with custom Content Type?
- Need to forward Data from WooCommerce Webhook sent to same site WordPress REST API custom endpoint
- Add Product Permalink in woocommerce admin order page
- Create custom admin page with custom text fields
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- Unable to show 4 products in a row
- Getting custom field data from cart page to checkout page in woocomerce [closed]
- Too few arguments at registering new templates in my plugin
- Remove Woocommerce product from cart with ajax/fetch
- Automatically change insurance quantity based on cart total [closed]
- I want to lists posts in wordpress to nearest location entered by the user
- Hide ‘Downloadable’ and ‘Virtual’ checkbox options from Woocommerce Variations?
- Integrate a Custom Post Type with Learndash Plugin
- Remove slug of multiple custom post types with and without hierarchical