Skip to content

Instantly share code, notes, and snippets.

@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 October 25, 2022 18:37
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') );
@igorbenic
igorbenic / fields.php
Created May 24, 2022 12:54
RCP New Fields
<?php
add_action( 'rcp_after_password_registration_field', 'rcp_my_custom_address_fields' );
function rcp_my_custom_address_fields() {
?>
<p id="rcp_address_country">
<label for="rcp_address_country">Country</label>
<input name="rcp_address_country" id="rcp_address_country" type="text"/>
@igorbenic
igorbenic / array.php
Last active May 8, 2022 23:02
Using a Recursive Function to Format Flat Arrays
<?php
$flat_array = [
[
'parent' => 0,
'id' => 1,
'title' => 'Parent 1',
'content' => [
'c12',