Skip to content

Instantly share code, notes, and snippets.

View mehrshaddarzi's full-sized avatar

Mehrshad Darzi mehrshaddarzi

View GitHub Profile
@mehrshaddarzi
mehrshaddarzi / product_attributes_filter.php
Created June 23, 2024 17:24
Get All Product Attributes by Category Slug WooCommerce
<?php
function get_attributes_by_product_cat($category_slug = null, $cacheHour = 6)
{
global $wpdb;
// Check Product Cat Slug
if (is_null($category_slug)) {
$query_object = get_queried_object();
$category_slug = $query_object->slug ?? '';
<style>
.modal-window {
position: fixed;
background-color: rgba(255, 255, 255, 0.25);
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 999;
visibility: hidden;
@mehrshaddarzi
mehrshaddarzi / run_time_microtime.php
Created April 6, 2024 08:47
Get Period Execute Run Time Script PHP (microtime)
// place this before any script you want to calculate time
$time_start = microtime(true);
// Check Time Spend
$time_end = microtime(true);
$execution_time = ($time_end - $time_start);
// Echo Date
echo date("H:i:s",$endtime-$starttime);
@mehrshaddarzi
mehrshaddarzi / option_cache_wordpress.php
Created January 31, 2024 03:58
Option Cache WordPress
// Check From Cache Option
if ($cache) {
$option = get_option('wp_hami_products');
if (!empty($option) and is_array($option) and isset($option['list']) and isset($option['expire']) and is_numeric($option['expire']) and $option['expire'] >= current_time('timestamp')) {
return [
'status' => true,
'list' => $option['list'],
'code' => $option['code'],
@mehrshaddarzi
mehrshaddarzi / Cronjob WordPress
Last active March 11, 2025 03:59
WordPress CronJob
$log_path = dirname(__FILE__).'/cron.txt';
$default_timezone = 'Asia/Tehran';
Date_default_timezone_set($default_timezone);
$now = date("Ymd @ H:i:s");
file_put_contents($log_path , $now.PHP_EOL, FILE_APPEND);
curl -s -o /dev/null -w "%{http_code}\n" "https://xxxxxx/?_sepidar_cron=product" >> /home/jaklin/public_html/status_code.txt 2>/dev/null
@mehrshaddarzi
mehrshaddarzi / dynamic_domain_wordpress.php
Created January 2, 2024 10:33
Dynamic Domain WordPress
<?php
define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);
@mehrshaddarzi
mehrshaddarzi / fix_authordiv_widget_admin_wordpress.php
Created December 12, 2023 13:07
Fix AuthrDiv MetaBox for WordPress
<?php
// Replace Authirdiv MetaBox for Increase Edit Page Speed
add_action('do_meta_boxes', 'action_change_author_meta_box');
function action_change_author_meta_box($screen)
{
remove_meta_box('authordiv', $screen, 'core');
add_meta_box('authordiv', 'شناسه نویسنده', 'action_post_author_meta_box', $screen, 'advanced', 'high');
}
@mehrshaddarzi
mehrshaddarzi / disable_wordPress_plugin.php
Last active December 12, 2023 05:08
Disable WordPress plugin
<?php
/*
* Plugin Name: Activate Plugins
*/
add_filter( 'option_active_plugins', function ( $plugins ) {
$actual_link = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if(strtoupper($_SERVER['REQUEST_METHOD']) == "POST" and strpos($actual_link, 'admin-ajax.php') !== false and isset($_POST['action']) and $_POST['action'] == "irk_quick_cart"){
@mehrshaddarzi
mehrshaddarzi / woocommerce_delete_cancelled_order.php
Last active May 14, 2025 05:50
Delete Cancelled WooCommerce Order Before X day Cron Job
<?php
// Remove Another Order Pending When create New Order in Checkout
// @see https://wp-kama.com/plugin/woocommerce/function/WC_Checkout::create_order
// @see https://wp-kama.com/plugin/woocommerce/function/WC_Checkout::process_checkout
// https://wp-kama.com/filecode/woocommerce/includes/class-wc-checkout.php#L484
add_action('woocommerce_checkout_create_order', 'checkout_order_created_delete_before_pending_customer_order', 20, 1);
function checkout_order_created_delete_before_pending_customer_order($order)
{
// Only Admin
@mehrshaddarzi
mehrshaddarzi / disable-wordpress-email.php
Created November 27, 2023 05:17
Disable WordPress Email
<?php
/*
* Plugin Name: Disable WordPress Emails
*/
add_filter('pre_wp_mail', '__return_true');