Fix Custom Post Type posts_per_page

function toolset_fix_custom_posts_per_page( $query_string ){
    if( is_admin() || ! is_array( $query_string ) )
        return $query_string;
 
    $post_types_to_fix = array(
        array(
            'post_type' => 'product',
            'posts_per_page' => 6
        )
    );
 
    foreach( $post_types_to_fix as $fix ) {
        if( array_key_exists( 'post_type', $query_string )
            && $query_string['post_type'] == $fix['post_type']
        ) {
            $query_string['posts_per_page'] = $fix['posts_per_page'];
            return $query_string;
        }
    }
 
    return $query_string;
}
 
add_filter( 'request', 'toolset_fix_custom_posts_per_page' );

Custom Currency/Symbol [Woocommerce]

Add Currency

add_filter( 'woocommerce_currencies', 'add_custom_currency' );
function add_custom_currency( $currencies ) {
  $currencies["PKR"] = 'Pakistani Rupee';
  return $currencies;
}

Add Symbol


add_filter('woocommerce_currency_symbol', 'add_custom_currency_symbol', 10, 2);
function add_custom_currency_symbol( $currency_symbol, $currency ) {
	switch( $currency ) {
	case 'PKR': $currency_symbol = 'Rs.'; break;
	}
	return $currency_symbol;
}

Order Filter by Payment [Woocommerce]

Add below code in theme function.php file

add_action( 'restrict_manage_posts', 'add_filter_by_payment_method_orders', 99 );
add_filter( 'request', 'add_filter_by_payment_method_orders_query', 99 );

function add_filter_by_payment_method_orders() {
    global $typenow;
    if ( 'shop_order' === $typenow ) {
        // get all payment methods
        $gateways = WC()->payment_gateways->payment_gateways();
        ?>
        <select name="_shop_order_payment_method" id="dropdown_shop_order_payment_method">
<option value=""><?php esc_html_e( 'All Payment Methods', 'text-domain' ); ?></option>
            <?php foreach ( $gateways as $id => $gateway ) : ?>
<option value="<?php echo esc_attr( $id ); ?>" <?php echo esc_attr( isset( $_GET['_shop_order_payment_method'] ) ? selected( $id, $_GET['_shop_order_payment_method'], false ) : '' ); ?>>
                <?php echo esc_html( $gateway->get_method_title() ); ?>
            </option>
            <?php endforeach; ?>
        </select>
        <?php
    }
}

function add_filter_by_payment_method_orders_query( $vars ) {
    global $typenow;
    if ( 'shop_order' === $typenow && isset( $_GET['_shop_order_payment_method'] ) && wc_clean( $_GET['_shop_order_payment_method'] )!="" ) {
        $vars['meta_key']   = '_payment_method';
        $vars['meta_value'] = wc_clean( $_GET['_shop_order_payment_method'] );
    }
    return $vars;
}

Custom Cart Item Count

Add below code where you want to show cart count.

<span class="count">
	<?php global $woocommerce; echo $woocommerce->cart->cart_contents_count; ?>
</span>

 

Add the below code in function.php file.

add_filter( 'woocommerce_add_to_cart_fragments', 'cart_count_fragments', 10, 1 );
function cart_count_fragments( $fragments ) {
	$val = WC()->cart->get_cart_contents_count();
	if($val == 0){
		$fragments['span.count'] = '<span class="count" style="opacity:0"></span>';
	}else{
		$fragments['span.count'] = '<span class="count" style="opacity:1">' . WC()->cart->get_cart_contents_count() . '</span>';
	}
    return $fragments;
}

Change Default jQuery in Wp

Add in function.php file

function replace_core_jquery_version() {
	wp_deregister_script( 'jquery' );
	wp_register_script( 'jquery', "https://code.jquery.com/jquery-3.4.1.min.js", array(), '3.1.1' );
}
add_action( 'wp_enqueue_scripts', 'replace_core_jquery_version' );