Skip to content

Instantly share code, notes, and snippets.

@igorbenic
igorbenic / field.php
Last active June 23, 2021 21:26
How to use the WooCommerce Postcode Validator | https://www.ibenic.com/woocommerce-postcode-validator
<?php
/**
* Shipping method id: rp_table_rate
* You can use any ID here and replace rp_table_rate to add this field to your shipping method settings page.
*/
add_filter( 'woocommerce_settings_api_form_fields_rp_table_rate', 'ibenic_add_postcodes_field_a_shipping_method' );
/**
* Add Postcodes field to the Table Rate
@igorbenic
igorbenic / validator.php
Created March 19, 2020 15:38
How to use the WooCommerce Postcode Validator | https://www.ibenic.com/woocommerce-postcode-validator
<?php
/**
* Used by shipping zones and taxes to compare a given $postcode to stored
* postcodes to find matches for numerical ranges, and wildcards.
*
* @since 2.6.0
* @param string $postcode Postcode you want to match against stored postcodes.
* @param array $objects Array of postcode objects from Database.
* @param string $object_id_key DB column name for the ID.
@igorbenic
igorbenic / remove-terms.php
Created March 12, 2020 12:16
Simple Sponsorships - Code Snippets
<?php
/**
* Remove Terms and Conditions Field
*/
add_filter( 'ss_form_sponsors_fields', 'ss_remove_terms_and_conditions' );
/**
* Filtering out the terms and conditions field
@igorbenic
igorbenic / disable-theme-comments.php
Last active February 21, 2024 21:34
Simple Feature Requests & GeneratePress snippets
<?php
add_action( 'jck_sfr_after_single_loop', 'jck_disable_theme_comments');
/**
* Disable the default theme comments form by disabling comments after the plugin comments form is rendered.
*/
function jck_disable_theme_comments() {
add_filter( 'comments_open', function( $open, $post_id ) {
if ( 'cpt_feature_requests' === get_post_type( $post_id ) ) {
@igorbenic
igorbenic / elementor-widget.php
Last active April 11, 2024 09:12
Ultimate Guide for JavaScript in Elementor Widgets
<?php
/**
* Plugin Name: Elementor Widget
* Text Domain: elementor-widget
* Domain Path: /languages
* Version: 0.1.0
*
* @package Elementor_Widget
*/
@igorbenic
igorbenic / App-1.js
Last active April 11, 2024 09:05
Headless WordPress: Displaying single articles | https://ibenic.com/headless-wordpress-displaying-articles
function App() {
const [loading, setLoading] = useState(false);
const [articles, setArticles] = useState([]);
const [notFoundSlugs, setNotFoundSlugs] = useState([]); // Adding not found slugs
// ... other code
}
@igorbenic
igorbenic / App-1.js
Last active April 11, 2024 09:05
Headless WordPress: React Router Pagination | https://ibenic.com/headless-wordpress-react-router-pagination
// Adding the React Router
import React, { useState, useEffect } from 'react';
import './App.scss';
import {
BrowserRouter as Router,
Switch,
Route,
Link,
useParams
} from "react-router-dom";
@igorbenic
igorbenic / form.html
Created January 7, 2020 22:59
Simple Giveaways - Remote Form
<!-- Replace:
{{GIVEAWAY_URL}} - The URL to the Giveaway main page (the giveaway landing page).
-->
<form id="giveasap_subscribe_form" class="giveasap_form" action="{{GIVEAWAY_URL}}" method="post">
<!-- Replace:
{{GIVEAWAY ID}} - the Giveaway ID, you can see the ID from the giveaway shortcode
-->
<input type="hidden" name="sg_giveaway_id" value="{{GIVEAWAY ID}}">
<!-- REQUIRED FIELD-->
@igorbenic
igorbenic / App-2.js
Last active July 8, 2022 12:43
Headless WordPress: Loading Posts & Pagination | https://ibenic.com/headless-wordpress-loading-posts-pagination
/**
* Returns articles for the current page.
* @param {integer} page
* @param {array} articles
* @param {object} articlesPages
*/
function getArticlesForPage( page = 1, articles, articlesPages ) {
// If we don't have them, return empty array
if ( ! articlesPages[ page ] ) {
return [];
@igorbenic
igorbenic / plugin-2.php
Created November 14, 2019 14:34
How to show the Correct Payment method on WooCommerce Subscriptions | https://ibenic.com/correct-payment-method-woocommerce-subscriptions
<?php
/**
* Plugin Name: Show the correct payment method in WooCommerce Subscription
* Description: Change the list of available payment methods to show the currently selected one instead of the default one.
* Version: 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
return;
}