Skip to content

Instantly share code, notes, and snippets.

View amiryousefi's full-sized avatar

Amir Yousefi amiryousefi

View GitHub Profile
@aahelali
aahelali / functions.php
Created May 16, 2019 10:10
WordPress Search by Title and ACF Fields or any WordPress Custom Fields
<?php
/**
* Extend WordPress search to include custom fields
*
* https://adambalee.com/search-wordpress-by-custom-fields-without-a-plugin/
*/
/**
* Join posts and postmeta tables
*
@aahelali
aahelali / functions.php
Created May 12, 2019 16:53
WooCommerce First Display In Stock Products in Loop
<?php
/**
* first show in stack products in woocommerce loop
* last show out of stack products in woocommerce loop
*/
add_filter( 'posts_clauses', 'wcss_manage_wp_posts_be_qe_posts_clauses', 1, 2 );
function wcss_manage_wp_posts_be_qe_posts_clauses( $pieces, $query ) {
global $wpdb;
if ( ($query->is_main_query() && is_archive() && is_woocommerce())
@aahelali
aahelali / functions.php
Created May 12, 2019 16:10
WooCommerce Remove Out of Stock Products in Related Products
<?php
/*
* Best way to remove out of stack products from related products
*/
add_filter('woocommerce_product_related_posts_query','aah_product_related_posts_query', 10, 2);
function aah_product_related_posts_query( $query, $product_id ) {
global $wpdb;
$query['join'] .= " LEFT JOIN wp_postmeta ON ( p.ID = wp_postmeta.post_id )";
$query['where'] .= " AND ( wp_postmeta.meta_key = '_stock_status' AND wp_postmeta.meta_value = 'instock' )";
@hallaji
hallaji / README.markdown
Last active August 9, 2017 02:49
Iranian National Identifier Validator

Iranian National Identifier Validator

A validator for Iranian (Persian) national identifier or social number

Languages

c#, java, javascript, php

Types

parameter: string (It doesn't support arabic or persian numbers)
return: boolean