Skip to content

Instantly share code, notes, and snippets.

@igorbenic
igorbenic / scroll.js
Created November 27, 2024 13:49
Horizontal Scroll Native
function nativeHorizontalScroll( id ) {
var elID = id;
var element = document.getElementById( id );
var scrolling = false;
var initialX = 0;
function getParent( node, id ) {
if ( node.id === id ) {
return node;
}
@igorbenic
igorbenic / remove_billing_shipping.php
Created October 25, 2024 20:24
WooCommerce Checkout Fields
<?php
/**
* NOTE: THIS IS NOT TESTED IN PRODUCTION.
*/
add_filter( 'woocommerce_checkout_fields', 'remove_billing_shipping_wc_fields' );
function remove_billing_shipping_wc_fields( $fields ) {
$billing_email = $fields['billing']['billing_email'];
@igorbenic
igorbenic / new.js
Created June 23, 2023 19:28
Programmatically Add a Block to WordPress | ibenic.com
var block = wp.blocks.createBlock('core/paragraph', {content: 'From Console'});
wp.data.dispatch('core/block-editor').insertBlocks(block);
@igorbenic
igorbenic / checkout-1.js
Created May 26, 2023 15:09
How to add a City Dropdown to WooCommerce Checkout
jQuery( function( $ ) {
var cities = wc_city_dropdown.cities;
wrapper_selectors = '.woocommerce-billing-fields,' +
'.woocommerce-shipping-fields,' +
'.woocommerce-address-fields';
$( document.body ).on( 'change refresh', 'select.country_to_state, input.country_to_state', function() {
var $wrapper = $( this ).closest( wrapper_selectors );
@igorbenic
igorbenic / widget-recent-posts.php
Created May 4, 2023 01:20
Developer Challenge: Create a Custom WordPress Widget | subscribe for more at https://www.ibenic.com/newsletter/
<?php
/**
* Plugin Name: Recent Widget Challenge from ibenic.com/newsletter
*/
/*
You will create a custom WordPress widget that displays a list of the most recent posts.
Each recent post should have:
@igorbenic
igorbenic / client.php
Last active March 27, 2023 02:24
Working with PHP SoapClient | ibenic.com
<?php
// Trace On so we can easily debug XML we constructed as its returns it.
$client = new \SoapClient(SOAP_SERVICE_URL, array('trace' => 1) );
$client->__setSoapHeaders( $header );
@igorbenic
igorbenic / abstract-1.php
Last active February 21, 2024 21:34
How to build WordPress Settings API as Framework | ibenic.com
<?php
namespace MySettingsFramework;
abstract class Settings {
/**
* Setting ID. Prefixes all options.
* @var string
*/
@igorbenic
igorbenic / live.php
Created November 23, 2022 22:17
A simple shortcode to display results from World Cup 2022 using api-football.com APIs
<?php
/**
* Plugin Name: Live API
*/
add_action( 'init', function(){
add_shortcode( 'live_api', 'live_api_shortcode' );
});
function live_api_shortcode() {
@igorbenic
igorbenic / hook_queue.php
Last active June 12, 2024 19:11
Custom WooCommerce Emails Delay
<?php
add_action( 'woocommerce_order_status_completed', 'queue_email', 10, 10 );
/**
* Generic function that will queue any action as we see fit.
*/
function queue_email( ...$args ) {
$filter = current_filter(); //woocommerce_order_status_completed
$delay = false;
@igorbenic
igorbenic / acf.js
Created June 3, 2022 15:19
ACF Repeater Fields - Filter by Price
(function($){
$(function(){
$(document.body).on( 'change', '#min_price, #max_price', function(){
var minPrice = parseFloat( $('#min_price').val() );
var maxPrice = parseFloat( $('#max_price').val() );
$('.item-list li').each(function(){
var price = parseFloat( $(this).attr('data-price') );