Skip to content

Instantly share code, notes, and snippets.

@igorbenic
igorbenic / add-cart-item.php
Last active February 21, 2024 21:34
Selling Simple Products as WooCommerce Subscriptions - Parts of code from tutorials | Selling Simple Products as WooCommerce Subscriptions - Admin | https://www.ibenic.com/selling-simple-products-woocommerce-subscriptions-front | https://www.ibenic.com/selling-simple-products-woocommerce-subscriptions-admin
<?php
namespace Simple_Product_Subscriptions;
class Cart {
/**
* Cart Hooks
@igorbenic
igorbenic / installer-2.php
Last active February 21, 2024 21:34
Working with Custom Tables in WordPress – Installing and Updating | https://ibenic.com
<?php
/**
* Installer class
*/
namespace MyPlugin;
class Installer {
// ... previous code
@igorbenic
igorbenic / checkout-form-final.php
Last active February 21, 2024 21:34
How to Customize WooCommerce Checkout Pages like a Hero | https://www.ibenic.com/customize-woocommerce-checkout-pages
<?php
/**
* Checkout Form
*
* This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-checkout.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@igorbenic
igorbenic / clauses.php
Last active February 21, 2024 21:34
Extending WP_Query with Custom Queries and Tables | https://www.ibenic.com/extending-wp-query-custom-queries-tables
<?php
add_filter( 'posts_clauses', 'filter_clauses', 10, 2 );
/**
* Filtering everything.
*
* @param array $clauses Array with all parts of the query.
* @param WP_Query $wp_query Object.
* @return string
@igorbenic
igorbenic / cron.php
Last active February 21, 2024 21:34
Automation on Post Publish | https://www.ibenic.com/automation-post-publish
<?php
add_action( 'publish_future_post', 'automation_on_publish', 20, 1 );
/**
* Create automate tasks on post publish.
*
* @param integer $post_id Post ID that is published.
*/
function automation_on_publish( $post_id ) {
@igorbenic
igorbenic / book_admin_enqueue.php
Last active February 21, 2024 21:34
Better WordPress Performance by Controlling Scripts | http://www.ibenic.com/better-wordpress-performance/
<?php
add_action( 'admin_enqueue_scripts', 'books_enqueue_scripts' );
function books_enqueue_scripts( $hook ){
$hook_scripts = false;
if( $hook_suffix == "post-new.php" && isset( $_GET["post_type"] ) && $_GET["post_type"] == "books" ){
$hook_scripts = true;
}
@igorbenic
igorbenic / app-1.js
Last active February 21, 2024 21:34
Using React to Render Content from WP REST API | https://ibenic.com/react-render-content-wp-rest-api
class App extends React.Component {
render() {
return (
bla
)
}
}
const element = <App />
@igorbenic
igorbenic / add.php
Last active February 21, 2024 21:34
How to Hook in WordPress Metadata | http://www.ibenic.com/hook-wordpress-metadata
<?php
// Should this data be added?
apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique );
// Do something before we add the data
do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value );
// Do Something after the data has been added
do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value );
@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 / plugin.php
Last active February 21, 2024 21:34
Show a WordPress Post in a Modal - Article on Ibenic.com
<?php
/**
* Plugin Name: IBenic Bootstrap Modal
* Plugin URI: http://www.ibenic.com/show-a-wordpress-post-in-a-modal/
* Description: Show an article in a modal on the same page.
* Version: 1.0
* Author: Igor benić
* Author URI: http://www.ibenic.com
* License: GPL2
*