Skip to content

Instantly share code, notes, and snippets.

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

Mohammed Saimon saimonh3

🏠
Working from home
View GitHub Profile
<?php
$_fp = fopen("php://stdin", "r");
while($string = fgets($_fp)){
$string = strtolower($string);
$string = str_replace(' ', '', $string);
$string = str_split($string);
$abc = range('a', 'z');
$gap = array_diff($abc, $string);
@saimonh3
saimonh3 / php
Created December 13, 2016 09:01
Getting User info using Facebook API.
<?php
session_start();
require_once __DIR__ . '/src/Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => 'APP_ID',
'app_secret' => 'APP_SECRET',
'default_graph_version' => 'v2.5',
]);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['user_birthday', 'user_location', 'user_website']; // optional
@saimonh3
saimonh3 / custom-post-type.php
Created December 24, 2016 04:34
WordPress Custom Post Type
<?php
//Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
function dwwp_register_post_type() {
$singular = 'Job';
$plural = 'Jobs';
$slug = str_replace( ' ', '_', strtolower( $singular ) );
@saimonh3
saimonh3 / remove-woocommerce-styles-scripts.php
Created January 18, 2017 14:37 — forked from gregrickaby/remove-woocommerce-styles-scripts.php
Remove WooCommerce styles and scripts.
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below into functions.php
/**
* Manage WooCommerce styles and scripts.
*/
function grd_woocommerce_script_cleaner() {
// Remove the generator tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
#!/bin/bash
clear
# Remove/Uninstall process
echo "WordPress Installation Starts :)"
if [[ $1 == "remove" ]]; then
# Grab the project name
if [[ -z $2 ]]; then
echo "WP Project to remove: "
function dokan_store_category_menu( $seller_id, $title = '' ) {
?>
<div id="cat-drop-stack">
<?php
$vendor = dokan()->vendor->get( get_query_var( 'author' ) );
$vendor_id = $vendor->get_id();
$products = $vendor->get_products();
$product_ids = [];
foreach ( $products->posts as $product ) {
@saimonh3
saimonh3 / class-wc-query.php
Last active May 6, 2019 21:38
Sort product by popularity with price greater than zero
add_action( 'woocommerce_product_query', function( $qeury ) {
if ( empty( $qeury->query_vars['orderby'] ) || 'popularity' !== $qeury->query_vars['orderby'] ) {
return;
}
add_filter( 'posts_clauses', function( $args ) {
$args['orderby'] = ' CASE wc_product_meta_lookup.min_price WHEN 0 THEN 1
ELSE -1
END ASC, wc_product_meta_lookup.total_sales DESC, wc_product_meta_lookup.product_id DESC
';
@saimonh3
saimonh3 / .zshrc
Created May 15, 2019 12:17 — forked from SumonMSelim/.zshrc
My Terminal Configuration (oh-my-zsh+iTerm2)
# Path to your oh-my-zsh installation.
export ZSH=/Users/SumonMSelim/.oh-my-zsh
# Set name of the theme to load.
ZSH_THEME="powerlevel9k/powerlevel9k"
POWERLEVEL9K_MODE="awesome-fontconfig"
# User configuration
export TERM="xterm-256color"
export SHELL="/bin/zsh"
@saimonh3
saimonh3 / stripe.php
Created September 22, 2019 03:29
Test Subscription
if ( 'invoice.payment_succeeded' == $event->type ) {
$user_id = $wpdb->get_var( "SELECT `user_id` FROM $wpdb->usermeta WHERE `meta_key` = '_stripe_subscription_id' AND `meta_value`='$invoice->subscription'" );
$period_start = date( 'Y-m-d H:i:s', $invoice->period_start );
$period_end = date( 'Y-m-d H:i:s', $invoice->period_end );
$order_id = get_user_meta( $user_id, 'product_order_id', true );
if ( $invoice->paid ) {
update_user_meta( $user_id, 'product_pack_startdate', $period_start );
update_user_meta( $user_id, 'product_pack_enddate', $period_end );
update_user_meta( $user_id, 'can_post_product', '1' );
@saimonh3
saimonh3 / dokan-upgrade-2.9.21.php
Created October 16, 2019 04:17
dokan-upgrade-2.9.21.php
<?php
/**
* Update post_author id for shop_orders
*
* @since 2.9.4
*
* @return void
*/
function dokan_update_variation_product_vendor() {