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 / update_plugin_programatically.php
Created November 17, 2019 17:01
Update WordPress Plugin Programatically.
<?php
function replace_plugin() {
// modify these variables with your new/old plugin values
$plugin_slug = 'wp-reset/wp-reset.php';
$plugin_zip = 'https://downloads.wordpress.org/plugin/wp-reset.latest-stable.zip';
$old_plugin_slug = 'reset-wp/reset-wp.php';
echo 'If things are not done in a minute <a href="plugins.php">click here to return to Plugins page</a><br><br>';
echo 'Starting ...<br><br>';
@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`