Created
March 26, 2021 15:55
-
-
Save stevegrunwell/393dc9ea09527c344b2b227c552c11e0 to your computer and use it in GitHub Desktop.
Limit Orders for WooCommerce - Custom Shortcodes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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