Skip to content

Instantly share code, notes, and snippets.

@igorbenic
igorbenic / App-2.js
Last active June 12, 2024 19:11
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;
}
@igorbenic
igorbenic / edit.js
Last active February 20, 2025 05:32
Gutenberg Components: ServerSideRender https://ibenic.com/gutenberg-components-server-side-render
/**
* WordPress dependencies
* https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/archives/edit.js
*/
// ... hidden code for tutorial purposes
import ServerSideRender from '@wordpress/server-side-render';
export default function ArchivesEdit( { attributes, setAttributes } ) {
const { showPostCounts, displayAsDropdown } = attributes;
@igorbenic
igorbenic / functions-2.php
Last active July 31, 2022 22:26
How to Move Payments on WooCommerce Checkout | https://www.ibenic.com/move-payments-woocommerce-checkout
<?php
/**
* Adding the payment fragment to the WC order review AJAX response
*/
add_filter( 'woocommerce_update_order_review_fragments', 'my_custom_payment_fragment' );
/**
* Adding our payment gateways to the fragment #checkout_payments so that this HTML is replaced with the updated one.
*/
function my_custom_payment_fragment( $fragments ) {
@igorbenic
igorbenic / Login.js
Last active September 5, 2019 09:10
Headless WordPress: Logging with Google and JWT | https://www.ibenic.com/headless-wordpress-google-jwt
import React from 'react';
import { TextControl, Button, Notice } from '@wordpress/components';
import LoginGoogle from './login/LoginGoogle'; //Adding Google Component
const axios = require('axios');
class Login extends React.Component {
constructor( props ) {
super( props );
// ... previous bindings are here.
// ...
.components-drop-zone__provider {
min-height: 100px;
height: auto;
width: 100%;
position: relative;
padding: 1em;
text-align: center;
background: rgba( 0, 0, 0, 0.05 );
// ...
import Dashboard from './components/Dashboard';
import AppNotices from './components/AppNotices';
import '@wordpress/notices';
function App() {
// ...
return (
<div className="App container">
/**
* Showing the general Profile view
*/
function Profile( { user }) {
return <div className="jumbotron">
Welcome { user.nickname }
<p>I think your name is { user.first_name } { user.last_name}</p>
</div>;
}
@import '~bootstrap/scss/bootstrap.scss';
@igorbenic
igorbenic / plugin-2.php
Last active February 21, 2024 21:34
How to create a Custom WooCommerce Product Type | https://www.ibenic.com/custom-woocommerce-product-type
<?php
// ...
class WC_Product_Type_Plugin {
/**
* Build the instance
*/
public function __construct() {