false,
'before' => '',
'after' => '',
)
);
if ( ! $ts || $ts <= time() ) {
return '';
}
wp_enqueue_script( 'pokit-countdown' );
return sprintf(
'
%3$s%4$s
',
$args['compact'] ? ' pokit-countdown--compact' : '',
(int) $ts,
$args['before'] ? '' . esc_html( $args['before'] ) . ' ' : '',
$args['after'] ? ' ' . esc_html( $args['after'] ) . '' : ''
);
}
/**
* [shipclock_countdown product_id="" product_sku="" until="" compact="false" before="" after=""]
*
* @param array $atts Atts.
* @return string
*/
public static function countdown( $atts ) {
$atts = shortcode_atts(
array(
'product_id' => '',
'product_sku' => '',
'until' => '',
'compact' => 'false',
'before' => '',
'after' => '',
),
$atts,
'shipclock_countdown'
);
$ts = 0;
if ( $atts['until'] ) {
try {
$ts = ( new DateTime( $atts['until'], wp_timezone() ) )->getTimestamp();
} catch ( Exception $e ) {
$ts = 0;
}
} else {
$p = self::product_from_atts( $atts );
$config = $p ? pokit_get_config( $p ) : null;
$ts = $config ? (int) $config['release_ts'] : 0;
}
return self::countdown_markup(
$ts,
array(
'compact' => wc_string_to_bool( $atts['compact'] ),
'before' => $atts['before'],
'after' => $atts['after'],
)
);
}
/**
* [shipclock_release_date product_id="" time="false"]
*
* @param array $atts Atts.
* @return string
*/
public static function release_date( $atts ) {
$atts = shortcode_atts(
array(
'product_id' => '',
'product_sku' => '',
'time' => 'false',
),
$atts,
'shipclock_release_date'
);
$p = self::product_from_atts( $atts );
$config = $p ? pokit_get_config( $p ) : null;
if ( ! $config ) {
return '';
}
return '' . esc_html( pokit_format_release( $config['release_ts'], wc_string_to_bool( $atts['time'] ) ) ) . '';
}
/**
* [shipclock_products limit="12" columns="4" orderby="date" order="DESC"]
*
* @param array $atts Atts.
* @return string
*/
public static function products( $atts ) {
$atts = shortcode_atts(
array(
'limit' => 12,
'columns' => 4,
'orderby' => 'date',
'order' => 'DESC',
),
$atts,
'shipclock_products'
);
$ids = get_posts(
array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => 200,
'fields' => 'ids',
'meta_key' => '_pokit_has_preorder', // phpcs:ignore WordPress.DB.SlowDBQuery
'meta_value' => 'yes', // phpcs:ignore WordPress.DB.SlowDBQuery
)
);
$ids = array_values( array_filter( $ids, 'pokit_has_any_preorder' ) );
if ( ! $ids ) {
return '' . esc_html__( 'No pre-orders available right now.', 'shipclock-pre-orders' ) . '
';
}
return do_shortcode(
sprintf(
'[products ids="%1$s" limit="%2$d" columns="%3$d" orderby="%4$s" order="%5$s"]',
esc_attr( implode( ',', $ids ) ),
absint( $atts['limit'] ),
absint( $atts['columns'] ),
esc_attr( $atts['orderby'] ),
esc_attr( $atts['order'] )
)
);
}
}