This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'posts_orderby', 'order_search_by_posttype', 10, 1 ); | |
function order_search_by_posttype( $orderby ){ | |
if( ! is_admin() && is_search() ) : | |
global $wpdb; | |
$orderby = | |
" | |
CASE WHEN {$wpdb->prefix}posts.post_type = 'product' THEN '1' | |
WHEN {$wpdb->prefix}posts.post_type = 'post' THEN '2' | |
WHEN {$wpdb->prefix}posts.post_type = 'page' THEN '3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'woocommerce_add_to_cart_fragments', function($fragments) { | |
ob_start(); ?> | |
<a href="<?php echo wc_get_cart_url(); ?>" class="fa fa-shopping-cart" title="Shopping Cart"><?php echo WC()->cart->get_cart_contents_count(); ?></a> | |
<?php $fragments['a.fa-shopping-cart'] = ob_get_clean(); | |
return $fragments; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var wpcf7Submit = $('.wpcf7-submit'); | |
document.addEventListener( 'wpcf7submit', function( event ) { | |
wpcf7Submit.attr('disabled', 'disabled'); | |
}, false); | |
document.addEventListener( 'wpcf7mailsent', function( event ) { | |
wpcf7Submit.removeAttr('disabled'); | |
}, false); | |
document.addEventListener( 'wpcf7mailfailed', function( event ) { | |
wpcf7Submit.removeAttr('disabled'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
You need to authorize your app with scope=public_content | |
Example: | |
https://api.instagram.com/oauth/authorize/?client_id=YOUR_CLIENT_ID&redirect_uri=REDIRECT_URL&response_type=token&scope=public_content | |
*/ | |
$get_my_insta = instagram_feed('USERNAME', 'APP_IP', 'ACCESS_TOKEN', 10); | |
if ( $get_my_insta ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_most_popular_products($atts = array()) | |
{ | |
extract($atts); | |
$posts_per_page = !isset( $posts_per_page ) ? 10 : $posts_per_page; | |
$order = !isset( $order ) ? "DESC" : $order; | |
$post_status = !isset( $post_status ) ? "publish" : $post_status; | |
$post_type = !isset( $post_type ) ? "product" : $post_type; | |
$args = array( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function pre_dump() { | |
echo '<pre style="background:#eee; border: solid 1px #ccc; color:#444; border-radius: 3px; padding:20px;">'; | |
foreach (func_get_args() as $arg) { | |
var_dump($arg); | |
echo "<br>"; | |
} | |
echo '</pre>'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function recursive_return_parent_array_by_value($needle, $haystack) { | |
$return = false; | |
foreach ($haystack as $key => $val) { | |
if (is_array($val)) { | |
$return = recursive_return_parent_array_by_value($needle, $val); | |
if( isset($return['found']) ) | |
return $return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getTaxTermsByOtherTaxTerm($taxonomy_1, $term_id, $taxonomy_2, $post_type = NULL) { | |
global $wpdb; | |
$post_type_q = !empty($post_type_q) ? "AND p.post_type = '$post_type'" : ""; | |
$sql = "SELECT r.object_id FROM $wpdb->terms AS t | |
INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id | |
INNER JOIN $wpdb->term_relationships AS r ON r.term_taxonomy_id = tt.term_taxonomy_id | |
INNER JOIN $wpdb->posts AS p ON (p.ID = r.object_id AND p.post_status = 'publish' $post_type_q) | |
WHERE tt.taxonomy = '$taxonomy_1' AND t.term_id = $term_id"; | |
$res = $wpdb->get_col($sql); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'woocommerce_add_cart_item_data', 'wdm_empty_cart', 10, 3); | |
function wdm_empty_cart( $cart_item_data, $product_id, $variation_id ) | |
{ | |
global $woocommerce; | |
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) { | |
if($cart_item['product_id'] == 512 ){ | |
$woocommerce->cart->remove_cart_item($cart_item_key); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// get next and prev products | |
// Author: Georgy Bunin (bunin.co.il@gmail.com) | |
// forked from https://gist.github.com/2176823 | |
function ShowLinkToProduct($post_id, $categories_as_array, $label) { | |
// get post according post id | |
$query_args = array( 'post__in' => array($post_id), 'posts_per_page' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'tax_query' => array( | |
array( | |
'taxonomy' => 'product_cat', |