Adding custom cart price with Ajax in wordpress

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 … Read more

fill form fields with ajax response

First, I can count on one finger the number of times A code which was developed in the hope of being “reusable” was actually reused. Write the code to the specification you can test against. “Reusable” is not a specification you can test against until you have a proper idea what will you need in … Read more

Why does my jQuery plugin show up as text in WordPress?

You can use this PHP code to output your slider’s initiator in your themes footer: add_action(‘wp_footer’,’initiate_unslider’); function initiate_unslider () { ?> <script src=”https://code.jquery.com/jquery-2.1.4.min.js”></script> <script src=”/path/to/unslider.js”></script> <script> $(document).ready(function() { $(‘.banner’).unslider(); }); </script> <?php } Also it’s safer to add a $(document).ready before initiating your slider, in case some necessary components of your page has not been … Read more

Jquery contact form to send mail to admin [closed]

Without php you can’t send an email. So as per your reference you have to use ajax and php. In wordpress ajax is little bit different as compared to normal ajax. You can check the link for how to use ajax in wordpress. https://www.smashingmagazine.com/2011/10/how-to-use-ajax-in-wordpress/ https://premium.wpmudev.org/blog/using-ajax-with-wordpress/?utm_expid=3606929-101.TxEXoCfwS1KxJG1JVvj_5Q.0&utm_referrer=https%3A%2F%2Fwww.google.co.in%2F https://www.sitepoint.com/how-to-use-ajax-in-wordpress-a-real-world-example/ Once you call the action inside ajax, in that … Read more

Twenty Fifteen: Change navigation menu behavior

In case anyone is interested, I think I managed to find a solution. Just had to add the following two lines of code just after the e.preventDefault(); line and before the _this.toggleClass( ‘toggle-on’ ); one: container.find( ‘.dropdown-toggle.toggle-on’ ).not( _this ).not( _this.parents( ‘.children, .sub-menu’ ).prev( ‘.dropdown-toggle’ ) ).removeClass( ‘toggle-on’ ).attr( ‘aria-expanded’, false ); container.find( ‘.children.toggled-on, .sub-menu.toggled-on’ … Read more

Loading external jQuery files with $

You can do this using follow snippet // Add scripts to wp_head() function child_theme_head_script() { ?> <!– Your HTML/JavaScript goes here –> <?php } add_action( ‘wp_head’, ‘child_theme_head_script’ );

Cherry Framework theme, JQuery is using HTTP not HTTPS

If the script is enqueued using wp_enqueue_script (as it “should” be) then you can modify the tag directly with a find and replace match to fix this using the script_loader_tag filter: add_filter(‘script_loader_tag’, ‘custom_https_fix’, 10, 2); function custom_https_fix($tag, $handle) { $match=”jquery.script.js”; // replace with actual script filename if (strstr($tag, $match)) {$tag = str_replace(‘http://’, ‘https://’, $tag);} return … Read more