Skip to content

Instantly share code, notes, and snippets.

View the-sufi's full-sized avatar
🏠
Working from home

the-sufi

🏠
Working from home
View GitHub Profile
@the-sufi
the-sufi / wp-auto-flush-w3tc.php
Last active April 6, 2020 01:22
WordPress - Weekly Flush all caches of W3 Total Cache Automatically
<?php
/** Flush all caches of W3TC
* Weekly basis
*/
//add weekly shcedule to wp cron
function dctit_cron_add_weekly( $schedules ) {
//adds once weekly to the existing schedules.
$schedules['weekly'] = array(
'interval' => 604800,
@the-sufi
the-sufi / woo-orders-auto-complete.php
Last active April 6, 2020 01:25
WooCommerce - Automactically Mark Orders as Complete
<?php
/**
* Auto Complete all WooCommerce orders.
*/
function dctit_custom_woocommerce_auto_complete_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
@the-sufi
the-sufi / woo-show-coupon-details-in-order-email.php
Created April 6, 2020 01:24
WooCommerce - show coupon code & description in order email
<?php
function dctit_add_coupon_to_email( $order ) {
$coupons = $order->get_items('coupon');
foreach ($coupons as $item_id => $item) {
$coupon = new WC_Coupon( $item['name'] );
$post = get_post($coupon->id);
echo "<p class='coupon-used'><span class='coupon-name'><b>Coupon: " . $item['name'] . "</b></span></p>";
echo "<p><span class='coupon-description'>" . $post->post_excerpt . "</span></p>";
}
@the-sufi
the-sufi / wp-hide-acf-menu.php
Last active July 30, 2021 01:56
Hide ACF menu from WP Admin
<?php
/**
* Hide ACF
*/
//hides settings icon from editor screen
function dctit_no_acf_icon() {
echo '<style>.acf-postbox:hover > .hndle .acf-hndle-cog {display: none !important;}.acf-postbox > .hndle:hover .acf-hndle-cog, .acf-postbox > .postbox-header:hover .acf-hndle-cog {display: none !important;}</style>';
}
add_action('admin_footer', 'dctit_no_acf_icon');
@the-sufi
the-sufi / wp-hide-youtube-related-videos.php
Created June 17, 2020 22:56
Hide Youtube related videos from other channels - WP oEmbed
@the-sufi
the-sufi / wp-custom-search-url.php
Created June 17, 2020 23:02
Change WordPress default search URL
<?php
/*
* Modify Default Search URL
* old url: domain.com?s=[search_term]
* new url: domain.com/search/[search_term]
*/
function dctit_change_search_url() {
if ( is_search() && ! empty( $_GET['s'] ) ) {
wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
exit();
@the-sufi
the-sufi / whmcs-oldest-ticket-reply-first.php
Last active June 17, 2020 23:13
WHMCS Client Area Ticket View - Show Oldest Reply First
<?php
/**
* code goes inside "includes/hooks" directory
*/
/**
* Client Area Ticket View - Show Oldest Reply First
* @param $vars
* @return array
*/
@the-sufi
the-sufi / whmcs-remove-announcements-from-clientarea-homepage.php
Last active May 29, 2023 14:16
WHMCS Remove Announcements from clientarea homepage
<?php
/**
* code goes inside "includes/hooks" directory
*/
/**
* Remove Announcements from homepage
*/
function dctit_remove_announcements_from_homepage( $home_page_panels) {
$home_page_panels->removeChild('Recent News');
@the-sufi
the-sufi / whmcs-show-credit-balance.php
Last active May 8, 2024 15:49
WHMCS Show Credit Balance on side panel/sidebar
<?php
/**
* code goes inside "includes/hooks" directory
*/
//for customizing nav menu items
use WHMCS\View\Menu\Item as MenuItem;
//for interacting with DB
use Illuminate\Database\Capsule\Manager as Capsule;
@the-sufi
the-sufi / wp-acf-overcome-draft-preview-issue.php
Last active August 25, 2020 15:09
ACF fields don't show up when previewing draft posts. This is an ugly hack to try and overcome that situation.
<?php
/**
* ACF fields don't show up when previewing draft posts. This is an ugly hack to try and overcome that situation.
*/
function dctit_hack_preview() {
$post_types = array ( 'post', 'page' );//add/edit/delete post types as needed
global $post;
if ( !in_array( $post->post_type, $post_types ) ) {
return;