add theme
This commit is contained in:
165
wp/wp-content/themes/medicalalert/woocommerce/single-product.php
Normal file
165
wp/wp-content/themes/medicalalert/woocommerce/single-product.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
get_header();
|
||||
|
||||
// start main content gathering
|
||||
while (have_posts()) {
|
||||
the_post();
|
||||
|
||||
// get the photo gallery out of output buffering because woo commerce is gross
|
||||
ob_start();
|
||||
do_action('woocommerce_before_single_product_summary');
|
||||
$wooGallery = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$currentProduct = site()->getPost($post, [
|
||||
"id",
|
||||
"permalink",
|
||||
"title",
|
||||
"excerpt",
|
||||
"acf.rating",
|
||||
"acf.total_ratings",
|
||||
"acf.activation_fee",
|
||||
"acf.about_product_lines",
|
||||
"meta._product_attributes",
|
||||
"meta._regular_price",
|
||||
"acf.fee_text",
|
||||
"acf.fee_type",
|
||||
"coupon"
|
||||
]);
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['variation_id'])) {
|
||||
$variation_id = intval($_POST['variation_id']);
|
||||
|
||||
// Check if the variation exists before adding it to the cart
|
||||
$variation = wc_get_product($variation_id);
|
||||
|
||||
if ($variation && $variation->is_type('variation')) {
|
||||
// Add the selected variation to the cart
|
||||
$cart_item_key = WC()->cart->add_to_cart($product->get_id(), 1, $variation_id);
|
||||
|
||||
if ($cart_item_key) {
|
||||
// Redirect to the cart or checkout page
|
||||
echo '<script>window.location.href = "' . wc_get_cart_url() . '";</script>';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
$allProducts = site()->getPosts(
|
||||
['post_type' => 'product', 'nopaging' => true],
|
||||
["id", "title", "permalink", "meta._product_attributes"]
|
||||
);
|
||||
$homeSafeStandardVsAutoAlertProducts = [];
|
||||
|
||||
$currentProductIsHomeSafe = false;
|
||||
$productsWithWearingStyle = [];
|
||||
$productsWithConnectionType = []; // non autoalert
|
||||
$HomeSafeProducts = []; // same as above, but autoalert only
|
||||
foreach ($allProducts as $lifelineProduct) {
|
||||
// hydrate all autoAlert products
|
||||
if (strpos($lifelineProduct["title"], "HomeSafe") !== false) {
|
||||
// die(var_dump($lifelineProduct));
|
||||
$autoAlertProducts[] = $lifelineProduct;
|
||||
}
|
||||
|
||||
// hydrate all products that have a "style" attribute and match the current product's "connection-type"
|
||||
if (is_array($lifelineProduct["_product_attributes"]) &&
|
||||
array_key_exists("style", $lifelineProduct["_product_attributes"]) &&
|
||||
is_array($currentProduct["_product_attributes"]) &&
|
||||
array_key_exists("connection-type", $currentProduct["_product_attributes"]) &&
|
||||
$currentProduct["_product_attributes"]["connection-type"]["value"] == $lifelineProduct["_product_attributes"]["connection-type"]["value"]
|
||||
) {
|
||||
$productsWithWearingStyle[] = $lifelineProduct;
|
||||
}
|
||||
|
||||
// hydrate all products that have a "connection-type" attribute and match the current product's "style"
|
||||
if (is_array($lifelineProduct["_product_attributes"]) &&
|
||||
array_key_exists("connection-type", $lifelineProduct["_product_attributes"]) &&
|
||||
is_array($currentProduct["_product_attributes"]) &&
|
||||
array_key_exists("style", $currentProduct["_product_attributes"]) &&
|
||||
$currentProduct["_product_attributes"]["style"]["value"] == $lifelineProduct["_product_attributes"]["style"]["value"]
|
||||
) {
|
||||
$productsWithConnectionType[] = $lifelineProduct;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// next, determine if the current product is HomeSafe
|
||||
if (strpos($currentProduct["title"], "HomeSafe") !== false) {
|
||||
$currentProductIsHomeSafe = true;
|
||||
//var_dump($currentProductIsHomeSafe);
|
||||
}
|
||||
|
||||
// next, determine which two products we should be switching between with
|
||||
// the radio button like choices shown in the template
|
||||
if (is_array($lifelineProduct["_product_attributes"]) &&
|
||||
array_key_exists("connection-type", $lifelineProduct["_product_attributes"]) &&
|
||||
is_array($currentProduct["_product_attributes"]) &&
|
||||
array_key_exists("connection-type", $currentProduct["_product_attributes"]) &&
|
||||
$currentProduct["_product_attributes"]["connection-type"]["value"] == $lifelineProduct["_product_attributes"]["connection-type"]["value"]
|
||||
) {
|
||||
// next, only show standard products that are of style "Wristband"
|
||||
if (is_array($lifelineProduct["_product_attributes"]["style"])) {
|
||||
if ($lifelineProduct["_product_attributes"]["style"]["value"] === "Wristband") {
|
||||
$homeSafeStandardVsAutoAlertProducts[] = $lifelineProduct;
|
||||
}
|
||||
} else {
|
||||
$homeSafeStandardVsAutoAlertProducts[] = $lifelineProduct; // this one should be the current autoalert product
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$OntheGoProducts = [];
|
||||
foreach ($allProducts as $llProduct) {
|
||||
if (strpos($llProduct["title"], "On the Go") !== false) {
|
||||
$ontheGoProducts[] = $llProduct;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$test = strtolower($currentProduct["title"]) === "On the Go";
|
||||
|
||||
$flexOutput = "";
|
||||
if (is_array(get_field('flex_content'))) {
|
||||
foreach (get_field('flex_content') as $flex) {
|
||||
$flexOutput .= site()->render($flex['acf_fc_layout'], $flex);
|
||||
}
|
||||
}
|
||||
|
||||
$variations = $product->get_available_variations();
|
||||
foreach ($variations as $variation) {
|
||||
$variation_id = $variation['variation_id'];
|
||||
$attributes = $variation['attributes']['attribute_rate-plan'];
|
||||
$price_html = $variation['price_html'];
|
||||
|
||||
}
|
||||
|
||||
$cart = WC()->cart;
|
||||
echo site()->render("single_product", [
|
||||
"variation" => $variations,
|
||||
"attributes" => $attributes,
|
||||
"gallery" => $wooGallery,
|
||||
"product" => $currentProduct,
|
||||
"add-to-cart-url" => do_shortcode("[add_to_cart_url id='".$currentProduct->ID."']"),
|
||||
"flex-content" => $flexOutput,
|
||||
"showHomesafeOptions" => strtolower(substr($currentProduct["title"], 0, 8)) === "homesafe",
|
||||
"homeSafeProducts" => array_reverse($homeSafeProducts),
|
||||
"showOTGOptions" => strtolower($currentProduct["title"]) === "on the go" || strtolower($currentProduct["title"]) === "on the go mini",
|
||||
"OTGProducts" => array_reverse($ontheGoProducts),
|
||||
|
||||
|
||||
// style link options
|
||||
"hasWearingStyle" => is_array($currentProduct["_product_attributes"]) && array_key_exists("style", $currentProduct["_product_attributes"]),
|
||||
"productsWithWearingStyle" => $productsWithWearingStyle,
|
||||
|
||||
// connection type options
|
||||
//"hasConnectionType" => is_array($currentProduct["_product_attributes"]) && array_key_exists("connection-type", $currentProduct["_product_attributes"]),
|
||||
"productsWithConnectionType" => array_reverse($productsWithConnectionType),
|
||||
"productsWithWearingStyle" => $productsWithWearingStyle,
|
||||
"autoAlertProducts" => array_reverse($autoAlertProducts),
|
||||
|
||||
"currentProductIsHomeSafe" => $currentProductIsHomeSafe,
|
||||
"homeSafeStandardVsAutoAlertProducts" => array_reverse($homeSafeStandardVsAutoAlertProducts),
|
||||
]);
|
||||
|
||||
get_footer('shop');
|
||||
Reference in New Issue
Block a user