138 lines
5.3 KiB
PHP
138 lines
5.3 KiB
PHP
<?php
|
|
get_header();
|
|
|
|
while (have_posts()) {
|
|
the_post();
|
|
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']);
|
|
$variation = wc_get_product($variation_id);
|
|
|
|
if ($variation && $variation->is_type('variation')) {
|
|
$cart_item_key = WC()->cart->add_to_cart($product->get_id(), 1, $variation_id);
|
|
|
|
if ($cart_item_key) {
|
|
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 = [];
|
|
$HomeSafeProducts = [];
|
|
foreach ($allProducts as $lifelineProduct) {
|
|
if (strpos($lifelineProduct["title"], "Home") !== false) {
|
|
$autoAlertProducts[] = $lifelineProduct;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
if (strpos($currentProduct["title"], "Home") !== false) {
|
|
$currentProductIsHomeSafe = true;
|
|
}
|
|
|
|
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"]
|
|
) {
|
|
if (is_array($lifelineProduct["_product_attributes"]["style"])) {
|
|
if ($lifelineProduct["_product_attributes"]["style"]["value"] === "Wristband") {
|
|
$homeSafeStandardVsAutoAlertProducts[] = $lifelineProduct;
|
|
}
|
|
} else {
|
|
$homeSafeStandardVsAutoAlertProducts[] = $lifelineProduct;
|
|
}
|
|
}
|
|
}
|
|
|
|
$OntheGoProducts = [];
|
|
foreach ($allProducts as $llProduct) {
|
|
if (strpos($llProduct["title"], "Mini Mobile System") !== false || strpos($llProduct["title"], "Mobile System") !== false) {
|
|
$ontheGoProducts[] = $llProduct;
|
|
}
|
|
}
|
|
|
|
$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, 4)) === "home",
|
|
"homeSafeProducts" => array_reverse($homeSafeProducts),
|
|
"showOTGOptions" => strtolower($currentProduct["title"]) === "mobile system" || strtolower($currentProduct["title"]) === "mini mobile system",
|
|
"OTGProducts" => array_reverse($ontheGoProducts),
|
|
"hasWearingStyle" => is_array($currentProduct["_product_attributes"]) && array_key_exists("style", $currentProduct["_product_attributes"]),
|
|
"productsWithWearingStyle" => $productsWithWearingStyle,
|
|
"productsWithConnectionType" => array_reverse($productsWithConnectionType),
|
|
"productsWithWearingStyle" => $productsWithWearingStyle,
|
|
"autoAlertProducts" => array_reverse($autoAlertProducts),
|
|
"currentProductIsHomeSafe" => $currentProductIsHomeSafe,
|
|
"homeSafeStandardVsAutoAlertProducts" => array_reverse($homeSafeStandardVsAutoAlertProducts),
|
|
]);
|
|
|
|
get_footer('shop');
|