get($args); return site()->render('testimonial-block', site()->getPost($post, [ 'title', 'thumbnail', 'position', 'quote', 'rating', ])); }; } public static function usd() { return function ($template, $context, $args, $source) { return "$" . number_format((float) $context->get($args), 2); }; } public static function fourColContent() { return function ($template, $context, $args, $source) { $content = get_field("flex_four_column_content", "options"); $icons = [ "truck", "chat-dots-fill", "arrow-counterclockwise", "credit-card", ]; $output = ""; foreach ($content as $i => $c) { $svg = site()->getAssetContents($icons[$i] . ".svg"); $output .= site()->renderTemplate(<<
{{{ icon }}}
{{{ headline }}} {{{ content }}}
HTML, [ "icon" => "$svg", "headline" => $c["headline"], "content" => $c["sub_headline"], ]); } return $output; }; } public static function locationTile() { return function ($template, $context, $args, $source) { return site()->render("location-tile", $context->get($args)); }; } public static function productTile() { return function ($template, $context, $args, $source) { $data = site()->getPost($context->get($args), [ "title", "thumbnail", "url", "woocommerce.price", "woocommerce.cartUrl", "woocommerce.attribute.msrp", ]); $data["savings"] = self::calcDifference($data["price"], $data["msrp"]); return site()->render("product-tile", $data); }; } public static function categoryBox() { return function ($template, $context, $args, $source) { $stuff = $context->get($args); return site()->render("page-tile", $stuff); }; } public static function renderBlock() { return function ($template, $context, $args, $source) { // if a page or product is chosen... if ($context->get($args)["page_product"]) { $post = $context->get($args)["page_product"]; if ($post->post_type === "page") { return site()->render("page-tile", site()->getPost($post, [ "title", "url", "thumbnail", ])); } $data = site()->getPost($post, [ "url", "id", "title", "thumbnail", "woocommerce.price", "woocommerce.attribute.msrp", "woocommerce.cartUrl", "woocommerce.sku", ]); $data["savings"] = self::calcDifference($data["price"], $data["msrp"]); return site()->render("product-tile", $data); } // if we got here, then hopefully the product_category is set if (!$context->get($args)["product_category"]) { return "No valid option chosen..."; } $termID = $context->get($args)["product_category"]; $term = get_term($termID); return site()->render("page-tile", site()->getQueriedObject($term, ['title', 'thumbnail', 'url'])); }; } public static function renderCallout() { return function ($template, $context, $args, $source) { // if a page or product is chosen... if ($context->get($args)["page_product"]) { $post = $context->get($args)["page_product"]; if ($post->post_type === "page") { return site()->render("page-callout", site()->getPost($post, [ "title", "url", "thumbnail", "excerpt", ])); } $data = site()->getPost($post, [ "url", "id", "title", "thumbnail", "woocommerce.price", "woocommerce.attribute.msrp", "woocommerce.cartUrl", "woocommerce.sku", ]); $data["savings"] = self::calcDifference($data["price"], $data["msrp"]); return site()->render("product-tile", $data); } // if we got here, then hopefully the product_category is set if (!$context->get($args)["category"]) { return "No valid option chosen..."; } $termID = $context->get($args)["category"]; $term = get_term($termID); return site()->render("category-callout", site()->getQueriedObject($term, [ 'title', 'thumbnail', 'url', 'description', ])); }; } public static function calcDifference($price, $msrp): string { if (!$price) { return ""; } if (!$msrp) { return ""; } $difference = $msrp - $price; if ($difference === 0) { return ""; } return round(($difference / $msrp) * 100); } public static function searchResultBox(string $type) { return function ($template, $context, $args, $source) use ($type) { $post = $context->get($args); if ($type === "product") { if ($post["post_type"] !== "product") { return ""; } $data = site()->getPost($post["id"], [ "url", "id", "title", "thumbnail", "woocommerce.price", "woocommerce.attribute.msrp", "woocommerce.cartUrl", "woocommerce.sku", ]); $data["savings"] = self::calcDifference($data["price"], $data["msrp"]); return site()->render("product-tile", $data); } if ($type === "page") { // var_dump($post); if ($post["post_type"] !== "page") { return ""; } return site()->render("page-tile", site()->getPost($post["id"], [ "url", "id", "title", "thumbnail", ])); } return site()->render("search-box", $context->get($args)); }; } }