I am looking for a feature to have zipcode, states and cities as dropdown and are chained. When states are selected first, cities are narrow down in a dropdown menu and zipcode can be populated automatically.
I found a very nice one:
https://wordpress.org/plugins/states-cities-and-places-for-woocommerce/
But zipcode is not populated with selected cities. I tried to contact the plugin authors but there is no feedback.
Or is there any other way to approach this? Thank you so much!
I made a small change on the plugin adding an onchange on the city select on the javascript pluging file:
states-cities-and-places-for-woocommerce/js/place-select.js
On this line:
$citybox.replaceWith( '<select name="' + input_name + '" id="' + input_id + '" class="city_select" placeholder="' + placeholder + '" onchange="getZipCode()"></select>' );
Then I added this rudementary script on the cart page :
<script>
function getZipCode() {
var city = document.getElementById("calc_shipping_city").value;
if(city=="Nameofthecity1"){calc_shipping_postcode.value = "111111";}
if(city=="Nameofthecity2"){calc_shipping_postcode.value = "222222";}
...
document.getElementById('calc_shipping_postcode').readOnly = true;
}
</script>
Related
I'd like to add a tooltip like this in order status, on mouse over:
I tried to use wc_help_tip as follows:
$help_tip = 'Ti do un suggerimento: studia!';
echo wc_help_tip(__($help_tip, 'mypluginname'));
As a result I get a similar behaviour: I display a question mark icon and on mouse over my custom text. I'd like to display my text in the same style as in WooCommerce order status column. Any suggestions?
I solved by myself using data-tip property as follows:
echo '<mark style="margin-bottom:2px;" class="order-status status-on-hold tips" data-tip="' . __('Document not created in MyPluginName', 'mypluginname') . '"><span>'. __('Not saved ', 'mypluginname') . '</span></mark><br />';
I would like to display a custom text message to notify customers that their selected input quantity (prior to clicking the "Add to Cart" button). This message will appear if the selected quantity is greater than the existing available stock quantity, right above the quantity selection within the individual product page. For example:
Existing Stock Quantity: 2
User Selects: >2
In such a scenario, I would like to tell the customer something like: "Your selected order quantity is greater than our existing stock. Please expect a delay of up to 2 weeks for our stock to be replenished."
I've tried to add the custom code into Code Snippets which looks something like that:
function display_order_quantity_exceeds_stock_quantity_text( $message, $product ) {
if( $product->woocommerce_quantity_input() > $product->get_stock_quantity()) {
$message = "Your selected order quantity is greater than our existing stock. Please expect a delay of up to 2 weeks for our stock to be replenished.";
}
return $message;
}
Does anyone know how I can obtain the woocommerce_quantity_input and get this to work?
Would prefer to have the solution just by adding a function into Code Snippets, rather than using Javascript (if possible).
Adding this jQuery code in your theme's footer.php will trigger an alert when user enters a value more than stock
<script type="text/javascript">
function show_error($field, $mesg) {
if ($field.prev('.error_msg').length) {
$field.prev('.error_msg').html('<p>' + $mesg + '</p>');
} else {
jQuery('<div class="error_msg" style="color:#f00"><p>' + $mesg + '</p></div>').insertBefore($field);
}
}
function remove_error($field) {
if ($field.prev('.error_msg').length) {
$field.prev('.error_msg').remove();
}
}
jQuery(".quantity input[name=quantity]").on('change', function(e) {
if (jQuery(this).val() > jQuery(this).attr("max")) {
show_error(jQuery(this).parent(".quantity"), "Your selected order quantity is greater than our existing stock. Please expect a delay of up to 2 weeks for our stock to be replenished")
} else {
remove_error(jQuery(this).parent(".quantity"));
}
})
</script>
You must have to enable Manage stock, and have set a stock number for this product to get it working.
I would do this through jQuery, so add this to your functions.php (the $src variable points to your JS file location in your theme folder):
function a3_enqueue_scripts() {
if(is_singular( 'product' )){
$handle = 'a3_wooc_js';
//path to your Javascript file
$src = get_theme_file_uri( '/js/a3_wooc.js' );
wp_enqueue_script( $handle, $src, array( 'jquery' ), false, false);
}
}
add_action( 'wp_enqueue_scripts', 'a3_enqueue_scripts' );
And something like this in the included JS file:
(function($){
$(document).ready(function(){
//the jQuery selector depends on your theme output for the quantity text box identifiers
$('[name="quantity"]').on('change', function(e){
var qty_box = $(this);
var error_message = $('<div class="error_msg">Your selected order quantity is greater than our existing stock. Please expect a delay of up to 2 weeks for our stock to be replenished</div>');
console.log(parseInt(qty_box.val()), parseInt(qty_box.attr('max')), qty_box.val() > parseInt(qty_box.attr('max')));
if(parseInt(qty_box.val()) > parseInt(qty_box.attr('max'))) {
// the action to take if the quantity exceeds max stock
if($('.quantity .error_msg').length < 1){
$('.quantity').prepend(error_message);
}
}
else {
$('.quantity .error_msg').remove();
}
});
});
})(jQuery);
I know there must be a solution to this I just can’t find it.
I want to have when users go to the Checkout page they can either click a button or select a checkbox for a certain predefined address and it will auto fill the address into the Shipping address box.
So meaning the user clicks <button> and it auto fills form with 123 Street, NY NY, 11111
Anyone have any idea how to do this?
Okay so I solved this (kinda)
On the Cart & Checkout Page: As I thought I didn't know WooCommerce well enough, so I changed it so now I have a Shipping Zone USA and whithin that I have 2 Shipping Types, the Free Shipment and a Flat Rate to anywhere else
On the Checkout Page I set a custom Javascript that when you click the button it auto fills the address in
Inside my functions.php
add_action( 'woocommerce_before_checkout_form', 'wnd_checkout_message', 10 );
function wnd_checkout_message( ) {
echo '<div class="wnd-checkout-message"><h3>Sending to X? Shipping is free!</h3><button onclick="changeShippingAddr();">Click here to ship</button></div><br />
';
And then on my actual Checkout Page I have a JavaScript:
<script>
function changeShippingAddr(){
document.getElementById("shipping_first_name").value = document.getElementById("billing_first_name").value;
document.getElementById("shipping_last_name").value = document.getElementById("billing_last_name").value;
document.getElementById("shipping_company").value = "COMPANY";
document.getElementById("shipping_country").value = "COUNTRY";
jQuery('body').trigger('update_checkout');
document.getElementById("shipping_state").value = "STATE";
jQuery('body').trigger('update_checkout');
document.getElementById("shipping_address_1").value = "ADDR";
document.getElementById("shipping_city").value = "CITY";
document.getElementById("shipping_postcode").value = "ZIP";
jQuery('body').trigger('update_checkout');
document.getElementById("select2-shipping_state-container").innerHTML= "State Name";
}
</script>
Which essentially sets the Name from Billing to Shipping and inserts a default Address so you don't need to type it in.
Thanks to all the helped out!
I followed the documentation in https://github.com/angular-ui/ng-grid/wiki/Sorting-and-filtering
but the only informaiton passed to the custom sort function are the values of the cells in the relevant column.
I'd like to access other columns within the custom sort function.
e.g.:http://plnkr.co/edit/FvcKQjkUv1eeoYPzjdRD?p=preview
I'd like to sort by name after taking the role into consideration. This would be easy if the row entity was supplied or something of sorts.
Thank you for any assistance.
Yuval
try to implement by header template and the whole control is in your hand fro sorting the callback goes to a function where you can do anything you want
var myHeaderCellTemplate = '<div class="ngHeaderSortColumn {{col.headerClass}}" ng-style="{cursor: col.cursor}" ng-class="{ ngSorted: !noSortVisible }">'+
'<div ng-click="sortByMyPreference()" ng-class="\'colt\' + col.index" class="ngHeaderText">{{col.displayName}}</div>'+
'<div class="ngSortButtonDown" ng-show="ID.down"></div>'+
'<div class="ngSortButtonUp" ng-show="ID.up"></div>'+
'<div class="ngSortPriority">{{col.sortPriority}}</div>'+
'<div ng-show="col.resizable" '+
'class="ngHeaderGrip" '+
'ng-click="col.gripClick($event)" '+
'ng-mousedown="col.gripOnMouseDown($event)"></div>';
here is the plunker http://plnkr.co/edit/OxyV1NlgznEJ8ulNAkt2?p=preview
i have left the implementation of sorting upto you click the Name Tab it will show you an alert and ID.down and ID.up you can toggle by true false to show arrows
I am a newbie in jQuery. I am trying to use the auto complete jQuery pluggn in my ASP.NET page .I downloaded the sample from the site and trying to rewrite it from PHP to ASP.NET
Can any one help me to rewrite it ?
<script type="text/javascript">
$().ready(function() {
function findValueCallback(event, data, formatted) {
$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
}
function formatItem(row) {
return row[0] + " (<strong>id: " + row[1] + "</strong>)";
}
function formatResult(row) {
return row[0].replace(/(<.+?>)/gi, '');
}
$("#imageSearch").autocomplete("images.php", {
width: 320,
max: 4,
highlight: false,
scroll: true,
scrollHeight: 300,
formatItem: function(data, i, n, value) {
return "<img src='images/" + value + "'/> " + value.split(".")[0];
},
formatResult: function(data, value) {
return value.split(".")[0];
}
});
and page contains
<input type="text" id='imageSearch' />
<input type="button" value="Get Value" />
Content of images.php
$term = $_REQUEST['q'];
$images = array_slice(scandir("images"), 2);
foreach($images as $value) {
if( strpos(strtolower($value), $term) === 0 ) {
echo $value . "\n";
}
}
I have some question on this
1 . I understand the images.php will return the list of images.Can any one provide me the format with an example ?Will that be a collection of list items,or divs or a single string seperated by some characters
2 . How the javscript is formating the output received.In my case i want to return a list of items(image names) and a Text (caption) with an id for it.So that users will see the image and the text in the option list and when he chooses,i want to show another page there ( i want to use the anchor tag there to navigate to another page with the id of option which user selected.
Kindly guide me Thanks in advance
1 . I understand the images.php will
return the list of images.Can any one
provide me the format with an example
?Will that be a collection of list
items,or divs or a single string
seperated by some characters
Not having run the code, it will be a list of strings separated by newline ("\n") chars; e.g.,:
"image1.jpg\nimage2.jpg\nimage3.jpg"
2 . How the javscript is formating the output received.In my case i want to return a list of items(image names) and a Text (caption) with an id for it.So that users will see the image and the text in the option list and when he chooses,i want to show another page there ( i want to use the anchor tag there to navigate to another page with the id of option which user selected.
You might want to have a look at JSON if you want to return structured data from the server.