Skip to content

Instantly share code, notes, and snippets.

View ihorduchenko's full-sized avatar
💭
Working

Ihor Duchenko ihorduchenko

💭
Working
View GitHub Profile
@ihorduchenko
ihorduchenko / added_to_cart.php
Created November 17, 2017 12:54
Automatically add products to cart when visit page
add_action( 'template_redirect', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
$articles = array(64);
$found = false;
// check if product already in cart
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
@ihorduchenko
ihorduchenko / functions.php
Created December 1, 2017 15:03
Get list of custom taxonomies of custom post type and list of the posts under them
//Downloads custom post type
function add_downloads_posts() {
register_post_type(
'download',
array(
'labels' => array(
'name' => 'Downloads',
'singular_name' => 'Downloads item',
'add_new' => 'Add new',
'add_new_item' => 'Add new',
@ihorduchenko
ihorduchenko / loop.js
Last active December 4, 2017 08:22
Increment in WP loop
(function ($) {
var i = 1;
$("input[name=your-name], input[name=your-phone], input[name=your-email], textarea[name=cover-letter], input[name=file-attachment]").each(function () {
i++;
var curParentName = $(this).parents("form").attr("name");
var inputName = curParentName[curParentName.length-1];
console.log(inputName);
$(this).attr("name", $(this).attr("name")+inputName);
})
})(jQuery);
@ihorduchenko
ihorduchenko / custom-date-time-display.php
Created December 14, 2017 14:38 — forked from jo-snips/custom-date-time-display.php
The Events Calendar: Custom Date/Time Display
<?php if (tribe_get_start_date() !== tribe_get_end_date() ) { ?>
<dt class="event-label event-label-start"><?php _e('Starts:', 'tribe-events-calendar') ?></dt>
<dd class="event-meta event-meta-start"><meta itemprop="startDate" content="<?php echo tribe_get_start_date( null, false, 'Y-m-d' ); ?>"/><?php echo tribe_get_start_date( null, false, 'F j, Y' ); ?></dd>
<dt class="event-label event-label-from"><?php _e('From:', 'tribe-events-calendar') ?></dt>
<dd class="event-meta event-meta-from"><meta itemprop="fromTime" content="<?php echo tribe_get_start_date( null, false, 'g:ia' ); ?>"/><?php echo tribe_get_start_date( null, false, 'g:ia' ); ?> to <?php echo tribe_get_end_date( null, false, 'g:ia'); ?></dd>
<?php } else { ?>
<dt class="event-label event-label-date"><?php _e('Date:', 'tribe-events-calendar') ?></dt>
<dd class="event-meta event-meta-date"><meta itemprop="startDate" content="<?php echo tribe_get_start_date( null, false, 'Y-m-d' ); ?>"/><?php echo tribe_get_start_date(); ?></d
@ihorduchenko
ihorduchenko / collections.liquid.html
Created February 23, 2018 13:49 — forked from rickydazla/collections.liquid.html
"Infinite" (non-auto) scrolling in Shopify collections
{% paginate collection.products by 20 %}
<ul class="collection-matrix">
{% for product in collection.products %}
<li id="product-{{ forloop.index | plus:paginate.current_offset }}">
{% include 'product' with product %}
</li>
{% endfor %}
<li class="top"><a href="#collectionpage">Back to Top</a> &uarr;</li>
{% if paginate.next %}
<li class="more">&darr; <a href="{{ paginate.next.url }}">More</a></li>
@ihorduchenko
ihorduchenko / bindScroll.js
Created July 20, 2018 08:54
Bind scroll to element(not "window")
document.addEventListener(
'scroll',
function(event){
var $elm = $(event.target);
if( $elm.is('.element1, .element2')){ // or any other filtering condition
// do some stuff
console.log('scrolling');
}
},
true // Capture event
@ihorduchenko
ihorduchenko / get-thumbnail.php
Last active October 15, 2018 10:34
Get page / post thumbnail
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?>
<?php echo $image[0]; ?>
@ihorduchenko
ihorduchenko / gulpfile.js
Created October 22, 2018 09:11
Gulpfile for minifying images using gulp and gulp-image NPM packages
const gulp = require('gulp'),
image = require('gulp-image');
const src = './uploads/**/*.{jpg,JPG,jpeg,JPEG,png,svg,gif}',
dist = './uploads-min/';
gulp.task('image', function () {
gulp.src(src)
.pipe(image({
pngquant: true,
@ihorduchenko
ihorduchenko / yoast_seo_prev_next_change.php
Created November 12, 2018 11:20 — forked from amboutwe/yoast_seo_prev_next_change.php
Remove or modify the Yoast SEO prev or next URLs. Only copy the section of code you need.
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Change Yoast SEO Prev/Next URL on some pages
* Credit: Yoast Team
* Last Tested: Jun 10 2017 using Yoast SEO 4.9 on WordPress 4.8
*/
add_filter( 'wpseo_next_rel_link', 'custom_change_wpseo_next' );
@ihorduchenko
ihorduchenko / ajax-load-more__footer.php
Last active December 12, 2018 13:21
Load more posts/pages/CPT's using Ajax