Skip to content

Instantly share code, notes, and snippets.

View DevWael's full-sized avatar
👨‍💻
WordPress-ing

Ahmad Wael DevWael

👨‍💻
WordPress-ing
View GitHub Profile
@DevWael
DevWael / saudi states.php
Created November 13, 2019 15:40
saudi arabia states array
<?php
$states = array(
'RIY' => esc_html__('Riyadh','porto'),
'MEC' => esc_html__('Mecca','porto'),
'MED' => esc_html__('Medina','porto'),
'BUR' => esc_html__('Buraydah','porto'),
'TAB' => esc_html__('Tabuk','porto'),
'DAM' => esc_html__('Dammam','porto'),
'AL ' => esc_html__('Al Ahsa','porto'),
@DevWael
DevWael / saudi_states.php
Last active November 13, 2019 15:42
saudi arabia states array
<?php
$states = array(
'RIY' => esc_html__('Riyadh','porto'),
'MEC' => esc_html__('Mecca','porto'),
'MED' => esc_html__('Medina','porto'),
'BUR' => esc_html__('Buraydah','porto'),
'TAB' => esc_html__('Tabuk','porto'),
'DAM' => esc_html__('Dammam','porto'),
'AL ' => esc_html__('Al Ahsa','porto'),
@DevWael
DevWael / woocommerce_saudi_kuwait_states.php
Created November 7, 2019 11:22
add saudi arabia and kuwait states to woocommerce
<?php
add_filter( 'woocommerce_states', 'dw_woocommerce_states' );
function dw_woocommerce_states( $states ) {
$states['KW'] = array(
'KWQ' => __('Dasmān','porto'),
'KWA' => __('Sharq','porto'),
'KWZ' => __('Mirgāb','porto'),
'KWW' => __('Jibla','porto'),
@DevWael
DevWael / check_woocommerce_cart.php
Created August 7, 2019 10:00
check if woocommerce cart is empty or not
<?php
function is_empty_cart() {
if ( ! class_exists( 'woocommerce' ) ) {
return false; //Woocpmmerce isn't isntalled
}
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
return false; //Cart is not empty
}
@DevWael
DevWael / generate_uuid.php
Created July 23, 2019 12:48
function to generate uuid in php
<?php
function prefix_generate_uuid() {
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
// 16 bits for "time_mid"
mt_rand( 0, 0xffff ),
@DevWael
DevWael / total_orders_count.php
Created July 9, 2019 11:48
get all orders count in woocommerce website
<?php
function prefix_orders_count() {
if ( ! class_exists( 'woocommerce' ) ) {
return false;
}
$args = [
'posts_per_page' => - 1,
'post_type' => 'shop_order',
'post_status' => 'any',
@DevWael
DevWael / wc_top_customers.php
Created July 9, 2019 10:12
List top woocommerce customers by their total spent
<?php
function prefix_top_customers_with_total_spend( $length = 5 ) {
if ( ! class_exists( 'woocommerce' ) ) {
return;
}
$data = [];
$args = [
'role' => 'customer',
'number' => - 1,
'fields' => 'ID'
@DevWael
DevWael / plugin_activation_and_uninstall_hooks.php
Last active July 29, 2019 09:59
use the following secured code in your plugin to run some logic on plugin activation, deactivation or uninstall events
<?php
//use the following code in your plugin to run some logic on plugin activation, deactivation or uninstall events
register_activation_hook( __FILE__, 'prefix_plugin_activate' );
function prefix_plugin_activate() {
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
$plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
@DevWael
DevWael / woocommerce_hooks.txt
Created July 8, 2019 08:19
List of woocommerce hooks with description
**Archive Page**
- Before Main Content `woocommerce_before_main_content`
- Before Shop Loop `woocommerce_before_shop_loop`
- Before Shop Loop Item `woocommerce_before_shop_loop_item`
- Before Shop Loop Item Title `woocommerce_before_shop_loop_item_title`
- After Shop Loop Item Title `woocommerce_after_shop_loop_item_title`
- After Shop Loop Item `woocommerce_after_shop_loop_item`
- After Shop Loop `woocommerce_after_shop_loop`
- After Main Content `woocommerce_after_main_content`
@DevWael
DevWael / country_codes.json
Last active July 1, 2019 12:39
Country Code alpha2 and alpha 3
{"AF":"AFG","AL":"ALB","DZ":"DZA","AS":"ASM","AD":"AND","AO":"AGO","AI":"AIA","AQ":"ATA","AG":"ATG","AR":"ARG","AM":"ARM","AW":"ABW","AU":"AUS","AT":"AUT","AZ":"AZE","BS":"BHS","BH":"BHR","BD":"BGD","BB":"BRB","BY":"BLR","BE":"BEL","BZ":"BLZ","BJ":"BEN","BM":"BMU","BT":"BTN","BO":"BOL","BA":"BIH","BW":"BWA","BV":"BVT","BR":"BRA","IO":"IOT","VG":"VGB","BN":"BRN","BG":"BGR","BF":"BFA","BI":"BDI","KH":"KHM","CM":"CMR","CA":"CAN","CV":"CPV","KY":"CYM","CF":"CAF","TD":"TCD","CL":"CHL","CN":"CHN","CX":"CXR","CC":"CCK","CO":"COL","KM":"COM","CD":"COD","CG":"COG","CK":"COK","CR":"CRI","CI":"CIV","CU":"CUB","CY":"CYP","CZ":"CZE","DK":"DNK","DJ":"DJI","DM":"DMA","DO":"DOM","EC":"ECU","EG":"EGY","SV":"SLV","GQ":"GNQ","ER":"ERI","EE":"EST","ET":"ETH","FO":"FRO","FK":"FLK","FJ":"FJI","FI":"FIN","FR":"FRA","GF":"GUF","PF":"PYF","TF":"ATF","GA":"GAB","GM":"GMB","GE":"GEO","DE":"DEU","GH":"GHA","GI":"GIB","GR":"GRC","GL":"GRL","GD":"GRD","GP":"GLP","GU":"GUM","GT":"GTM","GN":"GIN","GW":"GNB","GY":"GUY","HT":"HTI","HM":"HMD"