Skip to content

Instantly share code, notes, and snippets.

@Redolance
Redolance / create_or_update.php
Created June 13, 2018 00:44
Create custom filed , or just update it if its already exist .
$deal_id = $_POST['deal_id'];
if ( get_post_meta($deal_id, 'redo_expired_votes', true) ){
$ex_votes = get_post_meta($deal_id, 'redo_expired_votes', true);
$ex_vote = $ex_votes + 1;
update_post_meta($deal_id,'redo_expired_votes', $ex_vote);
}else{
add_post_meta($deal_id, 'redo_expired_votes', '1', true);
}
@Redolance
Redolance / get_param.js
Created June 13, 2018 02:16
get param from url with jquery
// the function
$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^]*)').exec(window.location.href);
if (results==null){
return null;
}
else{
return results[1] || 0;
}
}
@Redolance
Redolance / js-FileReader-for-image-without-upload.html
Last active June 14, 2018 00:16
preview image on browser before ubload js
<html>
<form id="form1" runat="server">
<input type='file' id="imgInp" />
<img id="blah" src="#" alt="your image" />
</form>
</html>
<script>
function readURL(input) {
@Redolance
Redolance / preview-image-in-browser.html
Created June 14, 2018 00:23
preview image in browser object URLs
<!-- The following code uses object URLs, which is much more efficient than data URL for viewing large images (A data URL is a huge string containing all of the file data, whereas an object URL, is just a short string referencing the file data in-memory):
-->
<!-- java script only -->
<html>
<img id="blah" alt="your image" width="100" height="100" />
<input type="file" onchange="document.getElementById('blah').src = window.URL.createObjectURL(this.files[0])">
</html>
<!-- version jquery. -->
@Redolance
Redolance / gist:e70ed0862bc57fb9315c9eaff1414151
Last active June 16, 2021 08:53
Woocommerce Turn Quantity Input to select box
/*
** source : https://www.cloudways.com/blog/change-display-quantity-select-box-in-woocommerce/
*/
function woocommerce_quantity_input($data = null) {
global $product;
if (!$data) {
$defaults = array(
'input_name' => 'quantity',
'input_value' => '1',
'max_value' => apply_filters( 'woocommerce_quantity_input_max', '', $product ),