Created
March 22, 2020 20:09
-
-
Save gaswirth/13c80cff0eefe64e5580f4d2d805dd17 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Render the latest product in the specified Product Category. | |
* | |
* @param array $atts The shortcode attributes | |
* @return string The formatted HTML | |
*/ | |
function rhdwp_woo_yayday_latest_bundle_shortcode( $atts ) { | |
$product_args = shortcode_atts( array( | |
'category' => null, | |
'title' => '', | |
), $atts ); | |
$product_cat = array( esc_attr( $product_args['category'] ) ); | |
$products = wc_get_products( array( | |
'limit' => 1, | |
'category' => $product_cat, | |
) ); | |
if ( $products ) { | |
$html = '<div class="single-product rhdwp-single-featured-product">'; | |
foreach( $products as $product ) { | |
$product_template = do_shortcode( "[product_page id={$product->get_id()}]" ); | |
$html .= $product_template; | |
} | |
$html .= '</div>'; | |
} | |
return $html; | |
} | |
add_shortcode( 'yayday_latest_bundle', 'rhdwp_woo_yayday_latest_bundle_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment