How to disable WC_AJAX::update_order_review() in checkout page? - ajax

I am trying to make the checkout process faster, currently, woocommerce is refreshing review-order based on choosing a state, and typing a zip code. While I use a flat rate, location is not an essential parameter in price.
How I can disable WC_AJAX::update_order_review() to prevent loading order review table?
Will disabling WC_AJAX::update_order_review() cause a problems?

I found the solution, add the following line in functions.php
add_action('wp_footer', 'sallar_woocommerce_custom_update_checkout', 50);
function sallar_woocommerce_custom_update_checkout()
{
if (is_checkout()) {
?>
<script type="text/javascript">
jQuery(document).ready($ => {
$('input').on('change', () => {
$('body').off('update_checkout');
});
});
</script>
<?php } }

Related

Call view in Laravel Controller with anchor tag

I need to call a view in a Laravel Controller, with parameters and with Anchor Tag.
I have this code in my controller:
return view('plans/editPlanView',
['plan' => $plan,
'patient' => $patient,
'aliments'=>$aliments, 'menu'=>$menu, 'tabName'=>$tabName]);
But i need to add an Anchor tag to land in a specific section of the page.
I can't use
return Redirect::to(URL::previous() . "#whatever");
proposed in other posts because i need to pass some parameters.
I think there are some base problem, trying with console this:
$('html, body').animate({
scrollTop: $('#whatever').offset().top
}, 1000);
scrolling to the desired section does not work.
it seems the page makes a small snap but always returns to the top.
Update
I have found the cause of the problem. At the bottom of the blade page I have the following code, without it the anchor tag works fine. Adding it the page makes a small scroll to return to the head. I need to use the datepicker, how can I fix the problem and get the anchor tag to work?
#push('scripts')
<script type="text/javascript">
$(document).ready(function () {
$('.date').datepicker({
firstDayOfWeek: 1,
weekDayFormat: 'narrow',
inputFormat: 'd/M/y',
outputFormat: 'd/M/y',
markup: 'bootstrap4',
theme: 'bootstrap',
modal: false
});
});
</script>
#endpush
You can create the method showPage() in your contoller for example TestController
public function showPage(Request $request)
{
$plan = $request->plan;
...
return view('plans/editPlanView', [
'plan' => $plan,
'patient' => $patient,
'aliments'=>$aliments, 'menu'=>$menu, 'tabName'=>$tabName
]);
}
Then create a route for rendering that view
Route::get('/someurl', 'TestController#showPage')->name('show-page');
And then in your methods you can use something like that:
$url = URL::route('show-page', ['#whatever']);
return Redirect::to($url)
I found a workaround, I added the disable attribute to the date input, in doing so, when the datepicker is initialized, the page does not scroll up. Then, as a last javascript statement I re-enabled the fields:
$('.date').prop("disabled", false);

Add jquery to Mganto pages inside admin panels [wysiwig editor]

How can I add jQuery code inside magento2 pages? For example I have a "Contact us" page. So I can edit the content inside contact us page by
Login to Admin panel
admin -> content -> Pages -> Contact us
I want to add some jQuery code.
So I write
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
<script>
jQuery(function($){
$(".mybox").on("click", function(){
MY CODE *******
});
});
</script>
Here the problem is: I have to call <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
Otherwise it will not work. How can I solve this?
ie. How can i add jquery code in wysiwig editor
Magento 2 Uses Require js
Try using
<script>
require([
'jquery'
], function ($) {
$(".mybox").on("click", function () {
console.log('your code starts here');
console.log('your code ends here');
});
});
</script>

TypeError: Product.ConfigurableSwatches is not a constructor in Magento 1.9.3

I'm using Magento 1.9.3.1 and facing below error on configurable product detail page
TypeError: Product.ConfigurableSwatches is not a constructor
Why am I getting this error and how can I fix it?
That seems to be a bug in Magento since I was able to reproduce it on a fresh installation when the following two conditions are meet:
Configurable product with a config attribute other than color.
Configurable swatches are disabled for that attribute.
You can solve it by checking if Product.ConfigurableSwatches exists before calling it:
1) Open this file: app/design/frontend/rwd/default/template/configurableswatches/catalog/product/view/type/configurable/swatch-js.phtml
2) Change this:
<script type="text/javascript">
document.observe('dom:loaded', function() {
var swatchesConfig = new Product.ConfigurableSwatches(spConfig);
});
</script>
To this:
<script type="text/javascript">
document.observe('dom:loaded', function() {
if (Product.ConfigurableSwatches) {
var swatchesConfig = new Product.ConfigurableSwatches(spConfig);
}
});
</script>

WordPress - AJAX Code Is Not Triggering Action

I am writing a plugin and the widget contains drop-down lists and needs to retrieve values for each successive drop-down list from the database using AJAX based on the previous drop-down list's selected value.
I am going off a slightly modified version of the code from the WordPress codex found here:http://codex.wordpress.org/AJAX_in_Plugins
For some reason the action function either isn't being called or the there is some error in my code:
// add action hooks
add_action('wp_footer', 'er_qm_ajax_handler' );
add_action('wp_ajax_repopulate_widget_club_type', 'repopulate_widget_club_type');
add_action('wp_ajax_nopriv_repopulate_widget_club_type', 'repopulate_widget_club_type');
// action for the wp_footer hook to insert the javascript
function er_qm_ajax_handler(){
?>
<script type="text/javascript" >
jQuery(document).ready(function($) {
jQuery('#widget_manufacturer').val('3').change(function(){
var manufacturer = $("#widget_manufacturer").val();
var data = {
action: 'repopulate_widget_club_type',
selected_manufacturer: manufacturer
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(ajaxurl, data, function(response) {
alert('Got this from the server: ' + response);
});
});
});
</script>
<?php
}
// The action function
function repopulate_widget_club_type(){
die("Got to the action");
}
Not exactly sure what I am doing wrong as I am getting no response from the AJAX post, I know that the jQuery .change() is working as I set up some alert()'s to test it out once I altered the dropdown lists values.
Any thoughts and help will be greatly appreciated, thanks!
You need to define the value of ajaxurl like this:
var ajaxurl = '<?php echo admin_url( 'admin-ajax.php' ); ?>'
It's prefferable to define it in javascript's global scope so before this line:
jQuery(document).ready(function($) {

Javascript error on $find for CollapsiblePanelExtender control for MasterPage scenario

I have a content page and a user control. The usercontrol uses CollapsiblePanelExtender. I have written the following javascript function on "onmouseout" of the panel.
<script language="javascript" type="text/javascript">
function doToggle()
{
var cpe = $find("CollapsiblePanelExtender1.ClientID");
//cpe._toggle();
if (!cpe.get_Collapsed()) {
cpe._doClose();
}
}
</script>
This conent page is part of master page. When I run the code I get javascript error. cpe is always null. How to use $find for CPE for a master page scenario? I also tried document.getElementById and passed the client id, still it didn't work. Please help.
Problem resolved by adding BehaviorID="cpe" to CollapsiblePanelExtender.
<ajax:CollapsiblePanelExtender ID="cpe" runat="Server" BehaviorID="cpe"
TargetControlID="SettingsContentPanel" CollapsedSize="0" Collapsed="True" ExpandControlID="SettingsTitlePanel"
CollapseControlID="SettingsTitlePanel" ScrollContents="False" ImageControlID="btnSettingsPopup"
SuppressPostBack="true" ExpandedImage="~/images/collapse.jpg" CollapsedImage="~/images/expand.jpg"
ExpandDirection="Vertical" AutoCollapse="false" AutoExpand="false" />
And then $find function will be able to find the control, code like:
function doToggle()
{
var cpe = $find("cpe");
if (!cpe.get_Collapsed())
{
cpe._doClose();
}
}

Resources