Skip to content

Instantly share code, notes, and snippets.

View moghanbari's full-sized avatar
🏠
Working from home

Mo Ghanbari moghanbari

🏠
Working from home
View GitHub Profile
// Using Repeat
const breakNumberIntoObject = (inputNumber) => {
if(!Number(inputNumber)) {
return;
}
const inputNumberArray = String(inputNumber).split('');
const output = {};
inputNumberArray.map((num) => {
@moghanbari
moghanbari / birthday.js
Last active July 9, 2022 03:27
Messy code with comments
// Returns number of remaining days to birthday
function birthday(inputDate) {
const today = new Date();
const birthday = new Date(inputDate);
const upcomingBday = new Date(today.getFullYear(), birthday.getMonth(), birthday.getDate());
// if birthday has already passed, set next year as birthday
if (today > upcomingBday) {
upcomingBday.setFullYear(today.getFullYear() + 1);
@moghanbari
moghanbari / wp_cach_sample.php
Created December 4, 2016 13:38
How to Work With Cache In Wordpress
<?php
function get_from_cach()
{
$c = wp_cache_get("my_cache_whatever_name", null);
if($c == null)
{
$c = $my_cache_whatever_value;
wp_cache_set( "my_cache_whatever_name", $c, null, 1000); // Last Number is Time In Minutes
}
return $c;
@moghanbari
moghanbari / single-user-coupon-code.php
Created February 20, 2016 11:40
Restrict Coupon Code for a user. if the user is who you want, the coupon code will add to the cart.
add_action( 'woocommerce_applied_coupon', 'check_for_individual_discount' );
function check_for_individual_discount()
{
global $woocommerce;
// Get All Coupons in Cart
$cart_coupons = $woocommerce->cart->applied_coupons;
$last_element = count($cart_coupons) -1;
$last_added_coupon = $cart_coupons[ $last_element ]; //get the last added coupon to the cart
@moghanbari
moghanbari / functions.php
Last active August 29, 2015 14:28 — forked from jameskoster/functions.php
WooCommerce - Remove product data tabs
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
function woo_remove_product_tabs( $tabs ) {
unset( $tabs['description'] ); // Remove the description tab
unset( $tabs['reviews'] ); // Remove the reviews tab
unset( $tabs['additional_information'] ); // Remove the additional information tab
return $tabs;
<?php
/**
* Order product collections by stock status, instock products first.
*/
class iWC_Orderby_Stock_Status
{
public function __construct()
{
@moghanbari
moghanbari / mq_product_second_title_metabox.php
Last active January 15, 2018 16:28
second title for a woocommerce product
<?php
/**
* Calls the class on the post edit screen.
*/
function call_mq_product_second_title_metabox() {
new mq_product_second_title_metabox();
}
if ( is_admin() ) {
add_action( 'load-post.php', 'call_mq_product_second_title_metabox' );