Try to change your add_custom_price_callback() as follows. Untested but should work.
function add_custom_price_callback() {
$custom_price = intval($_POST['p_m']);
$target_product_id = intval($_POST['s_o_v']);
foreach ( WC()->cart->get_cart() as $key=>$value ) {
//Single product
if ( $value['product_id'] == $target_product_id ) {
$value['data']->set_price($custom_price);
}
//For variation
if ( $value['variation_id'] == $target_product_id ) {
$value['data']->set_price($custom_price);
}
}
//to check if is work or not
wp_send_json(array($value['data']->get_price($custom_price)));
}
Related Posts:
- WooCommerce Ajax Cart Update Stopped Working
- Pass request headers in a jQuery AJAX GET call
- How to send multiple data fields via Ajax?
- Jquery Ajax Posting JSON to webservice
- Ajax Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource
- How to fix the ‘Missing required request header. Must specify one of: origin,x-requested-with’ Ajax Error
- What’s the point of the X-Requested-With header?
- How to manage ajax calls and JSON in wordpress
- WordPress AJAX File Upload – FrontEnd
- How to add a ” waiting” icon for an ajax in WP frontend?
- Can’t get a JSON object in response to an Ajax request with wp_ajax
- What is the simplest ajax upload plugin or script to be used with wordpress?
- Creating Ajax backend for Specialised Page Template? Should admin-ajax.php be used?
- WordPress Ajax URL for function in functions.php
- Infinite scroll / lazy loading with NextGen Gallery [closed]
- AJAX function returning -1
- call shortcode in javascript
- WP set auth cookie using Ajax is not saved to browser
- jQuery AJAX form validation
- Passing a varible from jQuery to PHP
- Proper way to load a single post via Ajax?
- Trying to get single posts to load on the front page via ajax
- ajax call in wordpress front end
- Ajax not firing properly using Firefox, but works in Chrome
- jQuery Ajax() doesn’t work when the page is accessed as a WordPress template page
- How to Use JSON With AJAX?
- wp_localize_script, variable is not defined in jquery
- How to load whole WordPress pages dynamically with AJAX/jQuery like this following website?
- Creating custom AJAX requests
- How to pass jQuery ajax URL value
- how to get the comment ID in the front end when the REPLY button is clicked?
- woocommerce target button with class after ajax update
- Admin wp_ajax hook returning 0
- wp_verify_nonce not working
- Tags in WordPress 3.2
- php ajax problem – weird 301 responses!
- WordPress customizer refresh screen after save
- How to get a value from PHP in Jquery through Ajax
- Not sure why wp_ajax isn’t working?
- Load created php file data via ajax
- Jquery not showing in homepage
- WordPress Ajax problem with undefined url
- How to get those data using with ajax json?
- Correct way to write jQuery functions in WordPress
- Intergrating agile carousel to wordpress: how to write the ajax_callback function
- In WooCommerce product archive, how can you also set the quantity to be added to cart by typing, instead of just by using +/-?
- Change “add to cart” button color based on Woocommerce product category [closed]
- AJAX Loaded Glossary like Search results with links to other entries from custom table
- How to Dynamically Load Content Into Body of Bootstrap Modal Window?
- Return an array from get_terms and store as JavaScript array for search autocomplete
- On screen music/audio player that grabs track URL [closed]
- Frontend Post with JQuery AJAX to Php Issue
- Trouble with WordPress Ajax Login System – 302
- WP http XML response HTML encoding and image display problems
- Using WP_Query to grab custom meta values, foreach to json object
- Add/remove action on jQuery toggle
- delete post meta by AJAX
- url – ajax loaded but no JS
- FacetWP – conditionally display facet labels
- Ajax form submit not working, returns 0
- Creating a new div onclick wordpress+ajax
- how to json_encode(); the Loop content so that the encoded array is [“0”:content, “1”:content]
- Properly embed javascript into WP (using function.php) – doesn’t work?
- jQuery tabs plugin with callback to fetch data
- WooCommerce event works in jQuery but not in JavaScript
- No Object Properties sending form through AJAX
- Redirect wp_dropdown_pages() to an AJax request?
- Custom AJAX form not working async
- Null/undefined return in WordPress AJAX request
- click event to unhide something after ajax not firing
- AJAX Success Function using JS substr() fails in WP 4.1 vs 4.0
- how to use wp_editor() here am getting empty result
- Manipulate retrieved ajax data in php
- Using Jquery submit with ajax request
- problems with jquery external rss feed integration
- WordPress Front-End Theme Editor
- Ajax page load in wordpress the right way?
- AJAX calendar navigation returns -1
- AJAX to add to cart multiple products woocommerce
- How to echo a PHP code into WooCommerce variation product?
- Get ajaxForm response value
- wordpress ajax upload media not working
- How to pull data from a table using wpdb?
- Is not using admin-ajax to ajax submissions okay?
- Autocomplete for titles via ajax – rework of past post away from like_escape()
- How to specify url for ajax call in wordpress plugin
- Possibility of creating a folder in the wordpress root install and installing a file there, all via plugin?
- Call admin ajax using absolute url? Relative URL breaks (frontend ajax)
- Ajax Request with jQuery not happening
- Page keeps refreshing with Ajax form
- wp_signon not working fine and 302 moved temporarily?
- Convert WordPress SACK code to new admin-ajax
- how to refresh index page without reloading browser using ajax
- Ajax request with jQuery without WP_ajax
- Ajax Query returns zero
- jQuery form plugin, submit in the wordpress way
- Contact Form 7 submission does not complete [closed]
- Using WP Ajax and jQuery to process multiple forms on the same page?
- Combo box populating a DIV using ajax/jquery
- Infinite Scroll applied to ajax loaded content