Skip to content

Instantly share code, notes, and snippets.

View melvinstanly's full-sized avatar
🌪️
Fast and Furious

Melvin Stanly melvinstanly

🌪️
Fast and Furious
View GitHub Profile
@melvinstanly
melvinstanly / file-preview.js
Last active February 8, 2019 09:54
File Preview Before Upload jQuery
function readURL(input){
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
//e.target.result ->contain image url in encoded form
//Do action with e.target.result here. Dont place outside onload function. won't work
};
reader.readAsDataURL(input.files[0]);
}
}
@melvinstanly
melvinstanly / woo-email-classes.php
Last active February 13, 2019 07:17
WooCommerce Email Related Codes
<?php
$mailer = WC()->mailer();
$mails = $mailer->get_emails();
$emails = wc()->mailer()->emails; // Contains all WooCommerce email classes with details
?>
@melvinstanly
melvinstanly / multi-string-replace.js
Last active February 13, 2019 07:24
Replace multiple strings in a single run in js
// Replace multiple strings with multiple values
var str = "I have a cat, a dog, and a goat.";
var mapObj = {
cat:"monkey",
dog:"goat",
goat:"cat"
};
str = str.replace(/cat|dog|goat/gi, function(matched){
@melvinstanly
melvinstanly / selectjs.txt
Last active February 13, 2019 07:24
jQuery select2
/* Dynamically add options to select field */
// Assuming 'custom-select' is the class of select field
<select class="custom-select">
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
</select>
@melvinstanly
melvinstanly / woo-product-titles.php
Created February 15, 2019 04:37
Woocommerce Product titles
<?php
// Change product title for products in shop page
remove_action( 'woocommerce_shop_loop_item_title','woocommerce_template_loop_product_title', 10 );
function change_product_title() {
$additional_text = ' More info';
echo '<h2 class="woocommerce-loop-product__title">' . get_the_title() .$additional_text.'</h2>';
}
add_action('woocommerce_shop_loop_item_title','change_product_title');
@melvinstanly
melvinstanly / price.php
Created February 20, 2019 11:00
Remove Price Symbol from string
<?php
$val = preg_replace('/&.*?;/', '', $val);
@melvinstanly
melvinstanly / slice-php.php
Created March 12, 2019 12:27
Php equivalent for .slice() of jquery
<?php
function strSlice($str, $start, $end) {
$end = $end - $start;
return substr($str, $start, $end);
}
$name = 'migthegreek';
// Get substr from index 3 to 6
echo strSlice($name, 3, 6);
@melvinstanly
melvinstanly / get-included-files.php
Created March 21, 2019 07:07
Get all php files added using include or require
<?php
$included_files = get_included_files();
foreach ($included_files as $filename) {
if( strpos( $filename, 'file_name') !== false ){ //Check if filename
echo $filename.'<br>';
}
}
<?php
if( is_wc_endpoint_url( 'order-received' ) ){
//To check if thank you page
}
if(is_checkout()){
// Check if in checkout page
}
@melvinstanly
melvinstanly / outlook.txt
Created May 23, 2019 11:42
Outlook version and conditional rule
Outlook Conditionall rules
<!--[if gte mso 9]>
<style type="text/css">
/* Your Outlook-specific CSS goes here. */
</style>
<![endif]-->