Skip to content

Instantly share code, notes, and snippets.

View Pratik-Jain12's full-sized avatar

Pratik Jain Pratik-Jain12

  • WP OnlineSupport
  • Ahmedabad, India
  • 15:52 (UTC +05:30)
View GitHub Profile
@Pratik-Jain12
Pratik-Jain12 / Optimize PHP MySql Join Query with MAX CASE
Created December 27, 2023 09:03
Optimize PHP MySql Join Query with MAX CASE.
There are four tables and we need to fetch the data with multiple Inner Joins. There are 14 inner joins which is taking long time to respond. This has been reduced to 3 inner joins with MySql MAX CASE which is quite fast in output with same result. I hope you can find this useful.
## Tables ##
WP_POSTS
WP_POSTMETA
WP_WOOCOMMERCE_ORDER_ITEMS
WP_WOOCOMMERCE_ORDER_ITEMMETA
## Old Query ##
@Pratik-Jain12
Pratik-Jain12 / edd-modify-country-state-data.php
Created September 15, 2022 06:00
Easy Digital Downloads - Modify Billing Country and Billing State Data
<?php
/* Function to modify EDD country data */
function modify_edd_countries( $countries ) {
/* Change Blank Option with String */
//$countries[''] = 'Select Country';
/* Remove first blank option */
//unset( $countries[''] );
@Pratik-Jain12
Pratik-Jain12 / woocommerce-apply-shipping-class.php
Last active September 7, 2022 12:04
Apply WooCommerce Shipping Class based on Coupon Code Applied
<?php
/**
* Apply WooCommerce shipping class based on coupon code applied on a product
* 26211 - This is product ID on which coupon code is applied
* 28760 - This is coupon code ID
* 142 - This is shipping class ID. You can find this when you inspect the shipping class table row
*/
function cart_apply_custom_shipping_class( $cart_contents ) {
@Pratik-Jain12
Pratik-Jain12 / edd-remove-admin-bar-menu.php
Created August 26, 2022 09:46
Remove EDD Admin Bar Menu - Easy Digital Downloads 3.X
<?php
/*
* Remove EDD admin bar menu
* Place below code to your theme / child theme functions.php file.
*/
remove_action( 'admin_bar_menu', 'edd_maybe_add_store_mode_admin_bar_menu', 9999 );
@Pratik-Jain12
Pratik-Jain12 / edd-download-history-modified-date.php
Created January 1, 2020 09:48
Display modified date of product in EDD product download history shortcode
<?php
/**
* Display product modified date in [download_history] shortcode.
*/
// Function to add extra column
function edd_add_download_history_column() {
echo '<th class="edd_download_download_name">'.esc_html__( 'Update Date', 'easy-digital-downloads' ).'</th>';
}
add_action( 'edd_download_history_header_end', 'edd_add_download_history_column' );
@Pratik-Jain12
Pratik-Jain12 / edd-total-downlods-no.php
Last active December 23, 2019 07:19
Display Total Number of EDD Products
<?php
/**
* Display total count of EDD products
* Display total count of EDD products with category also
* Use this shortcode 'edd_total_downlods' in any page or post where you want to show the EDD product number.
*/
function edd_render_total_downlods( $atts, $content ) {
$atts = shortcode_atts( array(
'category' => '',
@Pratik-Jain12
Pratik-Jain12 / edd-customer-file-download.php
Last active August 26, 2019 12:50
EDD Display File Download Count at Customers Listing Page
<?php
/**
* Function to add array after specific key
*/
function __edd_add_array(&$array, $value, $index, $from_last = false) {
if( is_array($array) && is_array($value) ) {
if( $from_last ) {
$total_count = count($array);
@Pratik-Jain12
Pratik-Jain12 / edd-remove-microdata.php
Last active July 24, 2019 07:53
Remove EDD schema.org microdata (In case your theme is already adding it)
<?php
// Remove EDD schema.org microdata (In case your theme is already adding it)
function _edd_add_schema_microdata( $microdata ) {
$microdata = false;
return $microdata;
}
add_filter( 'edd_add_schema_microdata', '_edd_add_schema_microdata' );
?>
@Pratik-Jain12
Pratik-Jain12 / edd-downloads-read-more-btn.php
Last active July 20, 2019 10:07
Add 'Read More' button to EDD [downloads] shortcode
<?php
// Function to add 'Read More' button at EDD [downloads] shortcode.
function _add_btn_edd_download_after() {
echo '<a class="button blue edd-submit" href="'. esc_url( get_permalink() ) .'" target="_blank">'. __('Read More') .'</a>';
}
add_action( 'edd_download_after', '_add_btn_edd_download_after' );
?>
@Pratik-Jain12
Pratik-Jain12 / edd-user-purchased-product.php
Last active March 22, 2019 13:55
Get User Purchased Download Products
// WP Query Parameters
$args = array (
'post_type' => 'download',
'post_status' => array( 'publish' ),
'order' => 'DESC',
'orderby' => 'post_date',
'posts_per_page' => 10,
'ignore_sticky_posts' => true,
'meta_query' => array(
array(