Skip to content

Commit

Permalink
feat: new shortcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
dkjensen committed Jun 3, 2021
1 parent 5640d22 commit 8abaf78
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -640,30 +640,43 @@ function wp_zoom_woocommerce_product_add_to_cart_url( $url, $product ) {
}
add_filter( 'woocommerce_product_add_to_cart_url', 'wp_zoom_woocommerce_product_add_to_cart_url', 10, 2 );

/**
* Display product excerpt
*
* @param array $args Shortcode data and arguments.
* @return void
*/
function wp_zoom_woocommerce_list_after_info( $args ) {
if ( $args['product'] ) {
$product = wc_get_product( $args['product'] );

/* phpcs:ignore WordPress.Security.EscapeOutput */
printf( '<p class="wp-zoom-list-item--info-excerpt">%s</p>', $product->get_short_description() );
}
}
add_action( 'wp_zoom_list_after_info', 'wp_zoom_woocommerce_list_after_info' );

/**
* Display buttons to register or view more details
*
* @param array $args Shortcode data and arguments.
* @return void
*/
function wp_zoom_woocommerce_list_info_action( $args ) {
if ( ! empty( $args['products'] ) && is_array( $args['products'] ) ) {
$product_id = current( $args['products'] );

if ( $args['product'] ) {
printf(
'<a href="%s" class="button wp-zoom-list-item--actions-button">%s</a>',
'<a href="%s" class="button wp-zoom-list-item--info-actions-button add_to_cart_button">%s</a>',
esc_url(
add_query_arg(
array(
'add-to-cart' => $product_id,
'add-to-cart' => $args['product'],
'occurrence_id' => $args['data']['occurrence_id'] ?? null,
),
get_permalink( $product_id )
get_permalink( $args['product'] )
)
),
esc_html__( 'Add to Cart', 'wp-zoom' )
esc_html__( 'Add to cart', 'wp-zoom' )
);
printf( '<a href="%s" class="button wp-zoom-list-item--actions-button">%s</a>', esc_url( get_permalink( $product_id ) ), esc_html__( 'View Details', 'wp-zoom' ) );
}
}
add_action( 'wp_zoom_list_after_info_actions', 'wp_zoom_woocommerce_list_info_action' );
16 changes: 16 additions & 0 deletions includes/wp-zoom-helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ function wp_zoom_get_purchase_products( string $webinar_id ) {
return $products;
}

/**
* Get the purchase product for a given webinar.
*
* @param string $webinar_id The webinar ID to check.
* @return null|integer
*/
function wp_zoom_get_purchase_product( string $webinar_id ) {
$products = wp_zoom_get_purchase_products( $webinar_id );

if ( ! empty( $products ) && is_array( $products ) ) {
return absint( current( $products ) );
}

return null;
}

/**
* Get webinars for a given post
*
Expand Down
31 changes: 20 additions & 11 deletions resources/scss/frontend.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

&-list-item {
display: flex;
margin: 0 0 2em;
margin: 0;
padding: 2em 0;
border-bottom: 1px solid #ccc;

&--date {
& &--date {
flex: 0 1 100px;
font-size: 14px;

Expand All @@ -14,13 +16,16 @@
}
}

&--calendar {
font-family: Arial, sans-serif;
& &--calendar {
text-align: center;
border: 5px solid #ccc;
border-radius: 5px;
padding: 4px 4px 6px;

* {
font-family: Arial, sans-serif;
}

&-month {
color: #fff;
background: #00a94f;
Expand All @@ -42,22 +47,26 @@
}
}

&--info {
& &--info {
flex: 1;
margin: 0 0 0 1em;

&-topic {
font-weight: 700;
margin: 0;
}
}

&--actions {
margin: 1em 0 0;
&-date {
font-weight: 700;
}

&-actions {
margin: 1em 0 0;

.button {
margin: 0 0.5em 0.5em 0;
display: inline-block;
.button {
margin: 0 0.5em 0.5em 0;
display: inline-block;
}
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions templates/shortcodes/list-single.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@
</div>
</div>
<div class="wp-zoom-list-item--info">
<h3 class="wp-zoom-list-item--info-topic"><?php echo esc_html( $args['data']['topic'] ); ?></h3>
<h3 class="wp-zoom-list-item--info-topic">
<?php
if ( $args['url'] ) {
printf( '<a href="%s">%s</a>', esc_url( $args['url'] ), esc_html( $args['data']['topic'] ) );
} else {
echo esc_html( $args['data']['topic'] );
}
?>
</h3>
<div class="wp-zoom-list-item--info-date"><?php echo esc_html( wp_zoom_format_date_time( $args['data']['start_time'] ) ); ?></div>

<?php do_action( 'wp_zoom_list_after_info', $args ); ?>

<div class="wp-zoom-list-item--actions">
<div class="wp-zoom-list-item--info-actions">
<?php do_action( 'wp_zoom_list_after_info_actions', $args ); ?>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions templates/shortcodes/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
<?php
if ( ! empty( $args['data'] ) ) {
foreach ( $args['data'] as $object ) {
$purchase_products = wp_zoom_get_purchase_products( $object['id'] );
$purchase_url = $purchase_products ? get_permalink( current( $purchase_products ) ) : '#';
$purchase_product = wp_zoom_get_purchase_product( $object['id'] );
$purchase_url = $purchase_product ? get_permalink( $purchase_products ) : null;

wp_zoom_load_template(
'shortcodes/list-single.php',
false,
array(
'data' => $object,
'products' => $purchase_products,
'product' => $purchase_product,
'url' => $purchase_url,
)
);
Expand Down

0 comments on commit 8abaf78

Please sign in to comment.