Skip to content

Instantly share code, notes, and snippets.

View pavlo-bondarchuk's full-sized avatar
🏠
remote

Pavlo Bondarchuk pavlo-bondarchuk

🏠
remote
View GitHub Profile
@pavlo-bondarchuk
pavlo-bondarchuk / functions.php
Created June 22, 2019 10:13
popup on event adding_to_cart
//add_action('wp_footer', 'show_template');
add_action(
'wp_footer',
function() {
?>
<script>jQuery( function( $ ) {
// Цепляемся за событие adding_to_cart
$( document.body ).on( 'adding_to_cart', function( event, button ) {
// Выцепляем инициатора события (ссылка/кнопка)
var $btn = $( button[0] );
@pavlo-bondarchuk
pavlo-bondarchuk / functions.php
Created May 31, 2019 11:02
WOOMS if( empty($data_api['image']['meta']['href']) ){ $product->set_status('draft'); } if( empty($data_api['description']) ){ $product->set_status('draft'); }
add_filter( 'wooms_product_save', function($product, $data_api){
if( empty($data_api['image']['meta']['href']) ){
$product->set_status('draft');
}
if( empty($data_api['description']) ){
$product->set_status('draft');
}
return $product;
}, 30, 2 );
@pavlo-bondarchuk
pavlo-bondarchuk / functions.php
Created May 21, 2019 16:21
cpt_hierarchical_taxonomy
add_action( 'init', 'register_faq_post_type' ); // register cpt faq
function register_faq_post_type() {
register_post_type( 'faq',
array(
'labels' => array(
'name' => 'Frequently Asked Questions',
'menu_name' => 'FAQ Manager',
'singular_name' => 'Question',
'all_items' => 'All Questions'
),
@pavlo-bondarchuk
pavlo-bondarchuk / README.php.detect_os.md
Created March 20, 2019 10:35
PHP: Detect user's operating system

Usage

It's that simple:

$os = getOS($_SERVER['HTTP_USER_AGENT']);

echo $os;
add_action('http_api_curl', 'sar_custom_curl_timeout', 9999, 1);
function sar_custom_curl_timeout( $handle ){
curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, 60 ); // 30 seconds. Too much for production, only for testing.
curl_setopt( $handle, CURLOPT_TIMEOUT, 60 ); // 30 seconds. Too much for production, only for testing.
}
// Setting custom timeout for the HTTP request
add_filter( 'http_request_timeout', 'sar_custom_http_request_timeout', 9999 );
function sar_custom_http_request_timeout( $timeout_value ) {
return 60; // 30 seconds. Too much for production, only for testing.
}
@pavlo-bondarchuk
pavlo-bondarchuk / functions.php
Last active February 3, 2019 16:35
Welcome Message for Repeat Customers
function wc_get_customer_orders() {
// Get all customer orders
$customer_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
) );
@pavlo-bondarchuk
pavlo-bondarchuk / javascript
Created January 30, 2019 14:50
lazy-load image
<img src="data:image/png;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" data-src="your-image-here">
<script>
function init() {
var imgDefer = document.getElementsByTagName('img');
for (var i=0; i<imgDefer.length; i++) {
if(imgDefer[i].getAttribute('data-src')) {
imgDefer[i].setAttribute('src',imgDefer[i].getAttribute('data-src'));
} } }
window.onload = init;
@pavlo-bondarchuk
pavlo-bondarchuk / blockClicks.js
Created December 28, 2018 14:18 — forked from lucas-pelton/blockClicks.js
Prevent multiple clicks and submissions in Contact Form 7
//http://epsiloncool.ru/programmirovanie/preventing-multiple-submits-in-contact-form-7
jQuery(document).on('click', '.wpcf7-submit', function(e){
if( jQuery('.ajax-loader').hasClass('is-active') ) {
e.preventDefault();
return false;
}
});
@pavlo-bondarchuk
pavlo-bondarchuk / .php
Created December 24, 2018 14:07
Поддержка Open Graph в WordPress / insert in head (wp_head)
// Поддержка Open Graph в WordPress
function add_opengraph_doctype( $output ) {
return $output . ' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"';
}
add_filter('language_attributes', 'add_opengraph_doctype');
function insert_fb_in_head() {
global $post;
if ( !is_singular())
return;
echo '<meta property="fb:admins" content="Ваш ID в Facebook"/>';
@pavlo-bondarchuk
pavlo-bondarchuk / .php
Created December 22, 2018 21:08
get first term of taxonomy current post / custom post type
$terms = get_the_terms( $post->ID, 'taxonomy-name' );
if( $terms ){
$term = array_shift( $terms );
// echo name or slug
echo $term->name; //or
echo $term->slug;
}