Skip to content

Instantly share code, notes, and snippets.

@stevegrunwell
Created March 26, 2021 15:55
Show Gist options
  • Save stevegrunwell/393dc9ea09527c344b2b227c552c11e0 to your computer and use it in GitHub Desktop.
Save stevegrunwell/393dc9ea09527c344b2b227c552c11e0 to your computer and use it in GitHub Desktop.
Limit Orders for WooCommerce - Custom Shortcodes
<?php
/**
* Plugin Name: Limit Orders for WooCommerce - Shortcode
* Description: Custom shortcode for displaying information from the Order Limiter.
* Author: Nexcess
* Author URI: https://nexcess.net
*/
use Nexcess\LimitOrders\OrderLimiter;
if ( ! shortcode_exists( 'limit-orders' ) ) :
/**
* Register a [limit-orders] shortcode.
*
* Anything inside the shortcode will be able to use the placeholders defined on the Limit
* Orders settings page.
*
* Example usage:
*
* [limit-orders]We can only accept {limit} orders a day, please check back at {next_interval:time}[/limit-orders]
*/
add_shortcode( 'limit-orders', function ( $atts, $content ) {
if ( ! class_exists( OrderLimiter::class ) ) {
return defined( 'WP_DEBUG' ) && WP_DEBUG
? '<!-- OrderLimiter class not found, is Limit Orders for WooCommerce active? -->'
: '';
}
$limiter = new OrderLimiter();
$placeholders = $limiter->get_placeholders( 'shortcode', $content );
return str_replace( array_keys( $placeholders ), array_values( $placeholders ), $content );
} );
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment