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 / line-break-after.css
Created July 29, 2020 13:38
Injecting line break via CSS
selector {
display: inline;
}
selector:after {
content: "\a";
white-space: pre;
}
@melvinstanly
melvinstanly / woo-delete-orders.php
Created July 8, 2020 13:43
Delete WooCommerce Orders Programmatically
<?php
global $wpdb;
$sql = "UPDATE wp_posts SET post_status = 'trash' WHERE post_type = 'shop_order';";
$wpdb->get_results($sql);
//Now all orders are moved to trash. Go to trash and click Empty Trash button
@melvinstanly
melvinstanly / ancestor-methods.txt
Created June 18, 2020 05:30
Differentiate between closest and parent methods in JQuery
This snippet just gives you an idea about the difference between .closest() and .parent() methods in jQuery.
closest()
----------
The closest() method does the following.
->Start with the current element i.e, `this`.
->Travel up the DOM tree until it finds a match to the selector supplied
-> returns an object with 0 or 1 element for each set in document order
@melvinstanly
melvinstanly / ui.txt
Created June 15, 2020 03:57
UI Recommendations
UI recommendations
Font Size - 36px
Line Height - 46px
Font Size - 22px
Line Height - 34px
Font Size - 18px
Line Height - 32px
@melvinstanly
melvinstanly / woo-attachments.php
Created June 10, 2020 09:31
WooCommerce Email Attachment from PHP File Upload Array
<?php
add_filter( 'woocommerce_email_attachments', 'webroom_attach_to_wc_emails', 10, 3);
function webroom_attach_to_wc_emails ( $attachments , $email_id, $order ) {
// Avoiding errors and problems
if ( ! is_a( $order, 'WC_Order' ) || ! isset( $email_id ) ) {
return $attachments;
}
// $upload_obj be upload object with file name, url and file path. Set file path to attachment
$path = isset($upload_obj['file']) ? $upload_obj['file'] : '';
if($url){
@melvinstanly
melvinstanly / flask-setup
Created June 3, 2020 14:35
Python flask setup instructions
1. Create a folder for your project Python House
2. cd to Python House
3. create a virtual environment for this project using the below code. Last venv is the folder name for virtual environment
python3 -m venv venv or python3 -m venv myenv
4. activate the virtual environment using the following command. Here venv is the folder name that is created is step 3
venv\Scripts\activate
5. Now you have activated and entered the virtual environment. You can just type deactivate to move out of virtual environment
6. Now install flask inside this virtual environment using the following command
pip install flask
@melvinstanly
melvinstanly / date-time.php
Created May 27, 2020 12:59
Get Date and Time for a particular time zone
<?php
$now = new DateTime(null, new DateTimeZone('Asia/Kolkata'));
$current_time = $now->format('H:i:s'); // For time
$current_time = $now->format('Y m d H:i:s'); //For date and time
?>
@melvinstanly
melvinstanly / file-extension-remover.js
Last active May 7, 2020 06:56
Extension free file name - Snippet to get file name after removing extension
function remove_file_extension( file_name ){
return file_name.slice(0, (file_name.lastIndexOf(".") - 1 >>> 0) + 1);
}
@melvinstanly
melvinstanly / add-to-cart-button.php
Created March 13, 2020 05:12
Disable add to cart button if product is not in stock
<?php
function change_loop_add_to_cart_button( $button, $product, $args = array() ) {
if( !$product->is_in_stock() ){
$button = '<a class="button disabled" style="cursor:not-allowed;color:#777;background-color:#aaa;">'.__('Sold Out', 'woocommerce').'</a>';
}
return $button;
}
add_filter( 'woocommerce_loop_add_to_cart_link', 'change_loop_add_to_cart_button', 20, 3 );
@melvinstanly
melvinstanly / customer-info.php
Created March 13, 2020 05:10
Show Customer Details in WooCommerce Email Template
<?php
// Use the below function anywhere in the template or use a hook where $order is available.
if( isset( $order ) ){ // Just a safety check
$user_id = $order->get_customer_id();
$user_info = get_userdata( $user_id );
echo $user_info->display_name;
}