From 8abaf78d255c7310a34ef1a9d8b52d9c2e4bb155 Mon Sep 17 00:00:00 2001 From: David Jensen Date: Thu, 3 Jun 2021 13:31:39 -0400 Subject: [PATCH] feat: new shortcodes --- .../wp-zoom-woocommerce-markup-products.php | 29 ++++++++++++----- includes/wp-zoom-helper-functions.php | 16 ++++++++++ resources/scss/frontend.scss | 31 ++++++++++++------- templates/shortcodes/list-single.php | 12 +++++-- templates/shortcodes/list.php | 6 ++-- 5 files changed, 70 insertions(+), 24 deletions(-) diff --git a/includes/integrations/woocommerce/wp-zoom-woocommerce-markup-products.php b/includes/integrations/woocommerce/wp-zoom-woocommerce-markup-products.php index 16dcfd3..8d877b4 100644 --- a/includes/integrations/woocommerce/wp-zoom-woocommerce-markup-products.php +++ b/includes/integrations/woocommerce/wp-zoom-woocommerce-markup-products.php @@ -640,6 +640,22 @@ 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( '

%s

', $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 * @@ -647,23 +663,20 @@ function wp_zoom_woocommerce_product_add_to_cart_url( $url, $product ) { * @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( - '%s', + '%s', 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( '%s', 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' ); diff --git a/includes/wp-zoom-helper-functions.php b/includes/wp-zoom-helper-functions.php index 6e45dd5..f3e584e 100644 --- a/includes/wp-zoom-helper-functions.php +++ b/includes/wp-zoom-helper-functions.php @@ -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 * diff --git a/resources/scss/frontend.scss b/resources/scss/frontend.scss index 8fc4852..ec31546 100644 --- a/resources/scss/frontend.scss +++ b/resources/scss/frontend.scss @@ -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; @@ -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; @@ -42,7 +47,7 @@ } } - &--info { + & &--info { flex: 1; margin: 0 0 0 1em; @@ -50,14 +55,18 @@ 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; + } } } } diff --git a/templates/shortcodes/list-single.php b/templates/shortcodes/list-single.php index 25a3daf..6e3dbfb 100644 --- a/templates/shortcodes/list-single.php +++ b/templates/shortcodes/list-single.php @@ -16,12 +16,20 @@
-

+

+ %s', esc_url( $args['url'] ), esc_html( $args['data']['topic'] ) ); + } else { + echo esc_html( $args['data']['topic'] ); + } + ?> +

-
+
diff --git a/templates/shortcodes/list.php b/templates/shortcodes/list.php index 3b6f865..1486ac2 100644 --- a/templates/shortcodes/list.php +++ b/templates/shortcodes/list.php @@ -11,15 +11,15 @@ $object, - 'products' => $purchase_products, + 'product' => $purchase_product, 'url' => $purchase_url, ) );