Last active
October 30, 2023 11:51
-
-
Save crazyyy/ff609c61d6e5decfb8c7ee7ff81d08dd to your computer and use it in GitHub Desktop.
[π¦ ACF Fake Field] ACF Fake Field Generator #php #wp #acf
This file contains hidden or 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 | |
// /* | |
function rand_float($st_num=0,$end_num=1,$mul=1000000) { | |
if ($st_num>$end_num) return false; | |
return mt_rand($st_num*$mul,$end_num*$mul)/$mul; | |
} | |
$query_args = array( | |
'post_type' => 'product', | |
'post_status' => 'publish', | |
'posts_per_page' => 150, | |
'paged' => (get_query_var('paged') ? get_query_var('paged') : 1), | |
'ignore_sticky_posts' => true, | |
'order' => 'ASC', | |
'orderby' => 'title', | |
); | |
$the_query = new WP_Query( $query_args ); | |
echo '<table>'; | |
echo '<tr>'; | |
echo '<th class="col-1">'; | |
echo 'Title'; | |
echo '</th>'; | |
echo '<th class="col-2">'; | |
echo 'Pricing Old'; | |
echo '</th>'; | |
echo '<th class="col-3">'; | |
echo 'Pricing New'; | |
echo '</th>'; | |
echo '<th class="col-4">'; | |
echo 'Items'; | |
echo '</th>'; | |
echo '<th class="col-5">'; | |
echo 'Updated'; | |
echo '</th>'; | |
echo '<th class="col-6">'; | |
echo 'New Pricing'; | |
echo '</th>'; | |
echo '</tr>'; | |
if ( $the_query->have_posts() ) : | |
while ( $the_query->have_posts() ) : $the_query->the_post(); // start loop | |
echo '<tr>'; | |
$price = get_field('price') ? get_field('price') : false; | |
$price_sale = get_field('price_sale') ? get_field('price_sale') : false; | |
$sale_in_percentage = get_field('sale_in_percentage'); | |
echo '<td>'; | |
the_title(); | |
echo '</td>'; | |
echo '<td>'; | |
echo $price; | |
echo '<br>'; | |
echo $price_sale; | |
echo '<br>'; | |
if ($sale_in_percentage) { | |
echo '<strong>%</strong> '; | |
echo $sale_in_percentage; | |
} | |
echo '</td>'; | |
echo '<td>'; | |
$price = get_field('price') ? get_field('price') : false; | |
$price_sale = get_field('price_sale') ? get_field('price_sale') : false; | |
echo $price; | |
echo '<br>'; | |
echo '<span>'; | |
if ($price_sale) { | |
if ($price_sale >= $price) { | |
echo '<span style="color: red;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} else { | |
echo '<span>'; | |
echo $price_sale; | |
echo '</span>'; | |
} | |
} | |
echo '</span>'; | |
echo '<br>'; | |
if ($sale_in_percentage) { | |
echo '<strong>%</strong> '; | |
echo $sale_in_percentage; | |
} | |
echo '</td>'; | |
echo '<td>'; | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item">Price</span>'; | |
echo '<span class="pack-items--item">Sale</span>'; | |
echo '<span class="pack-items--item"> * </span>'; | |
echo '</span>'; | |
if( have_rows('item_packages_and_quantity_variants') ): | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item pack-items--title">Standart</span>'; | |
echo '</span>'; | |
$default_counter = 0; | |
while ( have_rows('item_packages_and_quantity_variants') ) : the_row(); | |
/* | |
$price = get_sub_field('price') ? get_sub_field('price') : false; | |
$price_sale = get_sub_field('price_sale') ? get_sub_field('price_sale') : false; | |
$default_package = get_sub_field('default_package'); | |
$temp_new_price = ''; | |
$temp_new_sale = false; | |
$is_a_float = (bool)random_int(0, 1); | |
$is_have_sale = (bool)random_int(0, 1); | |
$is_default = (bool)random_int(0, 1); | |
$price_new = rand_float(0.1, 600, 1000000); | |
$price_new = abs($price_new); | |
$sale_in_percent = rand(1, 15); | |
$sale_in_percent = abs($sale_in_percent); | |
$sale_in_numbers = $price_new / 100 * $sale_in_percent; | |
$price_sale_new = $price_new - $sale_in_numbers; | |
if ($is_a_float) { | |
$price_new = number_format($price_new, 2); | |
$price_sale_new = number_format($price_sale_new, 2); | |
} else { | |
$price_new = number_format($price_new, 0); | |
$price_sale_new = number_format($price_sale_new, 0); | |
} | |
$price_new = strval( $price_new ); | |
$price_sale_new = strval( $price_sale_new ); | |
update_sub_field('price', $price_new, get_the_ID()); | |
update_sub_field('price_sale', false, get_the_ID()); | |
if ($is_have_sale) { | |
update_sub_field('price_sale', $price_sale_new, get_the_ID()); | |
} | |
update_sub_field('default_package', 0, get_the_ID()); | |
if ($is_default) { | |
update_sub_field('default_package', 1, get_the_ID()); | |
} | |
*/ | |
$price = get_sub_field('price') ? get_sub_field('price') : false; | |
$price_sale = get_sub_field('price_sale') ? get_sub_field('price_sale') : false; | |
$default_package = get_sub_field('default_package'); | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item">'; | |
echo $price; | |
echo '</span>'; | |
echo '<span class="pack-items--item">'; | |
if ($price_sale) { | |
if ($price_sale > $price) { | |
echo '<span style="color: red;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} else if ($price_sale === $price) { | |
echo '<span style="color: red;">'; | |
echo $price_sale; | |
echo '</span><br>'; | |
echo '<span style="color: green;">'; | |
$price_sale_new = $price_sale - ($price_sale / 100 * 5); | |
echo $price_sale_new; | |
update_sub_field('price_sale', $price_sale_new, get_the_ID()); | |
echo '</span>'; | |
} else { | |
echo '<span style="color: #dde3e7;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} | |
} | |
echo '</span>'; | |
echo '<span class="pack-items--item">'; | |
if ($default_package) { | |
if ($default_counter === 0) { | |
echo '<span>'; | |
echo 'Default'; | |
echo ' (' . $default_counter . ')'; | |
echo '</span>'; | |
} | |
if ($default_counter >= 1) { | |
echo '<span style="color: red;">'; | |
update_sub_field('default_package', 0, get_the_ID()); | |
echo 'Default'; | |
echo ' (' . $default_counter . ')'; | |
echo '</span>'; | |
} | |
$default_counter++; | |
} | |
echo '</span>'; | |
echo '</span>'; | |
endwhile; | |
endif; | |
if( have_rows('dosage_option') ): | |
$default_counter = 0; | |
while ( have_rows('dosage_option') ) : the_row(); | |
if( have_rows('qty_and_cost_variants_for_this_dose') ): | |
echo '<span class="pack-items"> | |
<span class="pack-items--item pack-items--title">Dosage</span> | |
</span>'; | |
while( have_rows('qty_and_cost_variants_for_this_dose') ): the_row(); | |
/* | |
$price = get_sub_field('price') ? get_sub_field('price') : false; | |
$price_sale = get_sub_field('price_sale') ? get_sub_field('price_sale') : false; | |
$default_package = get_sub_field('default_package'); | |
$temp_new_price = ''; | |
$temp_new_sale = false; | |
$is_a_float = (bool)random_int(0, 1); | |
$is_have_sale = (bool)random_int(0, 1); | |
$is_default = (bool)random_int(0, 1); | |
$price_new = rand_float(0.1, 600, 1000000); | |
$price_new = abs($price_new); | |
$sale_in_percent = rand(1, 15); | |
$sale_in_percent = abs($sale_in_percent); | |
$sale_in_numbers = $price_new / 100 * $sale_in_percent; | |
$price_sale_new = $price_new - $sale_in_numbers; | |
if ($is_a_float) { | |
$price_new = number_format($price_new, 2); | |
$price_sale_new = number_format($price_sale_new, 2); | |
} else { | |
$price_new = number_format($price_new, 0); | |
$price_sale_new = number_format($price_sale_new, 0); | |
} | |
$price_new = strval( $price_new ); | |
$price_sale_new = strval( $price_sale_new ); | |
update_sub_field('price', $price_new, get_the_ID()); | |
update_sub_field('price_sale', false, get_the_ID()); | |
if ($is_have_sale) { | |
update_sub_field('price_sale', $price_sale_new, get_the_ID()); | |
} | |
update_sub_field('default_package', 0, get_the_ID()); | |
if ($is_default) { | |
update_sub_field('default_package', 1, get_the_ID()); | |
} | |
*/ | |
$price = get_sub_field('price') ? get_sub_field('price') : false; | |
$price_sale = get_sub_field('price_sale') ? get_sub_field('price_sale') : false; | |
$default_package = get_sub_field('default_package'); | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item">'; | |
echo $price; | |
echo '</span>'; | |
echo '<span class="pack-items--item">'; | |
if ($price_sale) { | |
if ($price_sale > $price) { | |
echo '<span style="color: red;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} else if ($price_sale === $price) { | |
echo '<span style="color: red;">'; | |
echo $price_sale; | |
echo '</span><br>'; | |
echo '<span style="color: green;">'; | |
$price_sale_new = $price_sale - ($price_sale / 100 * 5); | |
echo $price_sale_new; | |
update_sub_field('price_sale', $price_sale_new, get_the_ID()); | |
echo '</span>'; | |
} else { | |
echo '<span style="color: #dde3e7;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} | |
} | |
echo '</span>'; | |
echo '<span class="pack-items--item">'; | |
if ($default_package) { | |
if ($default_counter === 0) { | |
echo '<span>'; | |
echo 'Default'; | |
echo ' (' . $default_counter . ')'; | |
echo '</span>'; | |
} | |
if ($default_counter >= 1) { | |
echo '<span style="color: red;">'; | |
update_sub_field('default_package', 0, get_the_ID()); | |
echo 'Default'; | |
echo ' (' . $default_counter . ')'; | |
echo '</span>'; | |
} | |
$default_counter++; | |
} | |
echo '</span>'; | |
echo '</span>'; | |
endwhile; | |
endif; | |
endwhile; | |
endif; | |
echo '</td>'; | |
echo '<td class="second result">'; | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item">Price</span>'; | |
echo '<span class="pack-items--item">Sale</span>'; | |
echo '<span class="pack-items--item"> * </span>'; | |
echo '</span>'; | |
$default_counter = 0; | |
$i = 0; | |
$product_price = false; | |
$product_price_sale = false; | |
if( have_rows('item_packages_and_quantity_variants') ): | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item pack-items--title">Standart</span>'; | |
echo '</span>'; | |
while ( have_rows('item_packages_and_quantity_variants') ) : the_row(); | |
$title = get_sub_field('package'); | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item pack-items--title">' . $title . '</span>'; | |
echo '</span>'; | |
$price = get_sub_field('price') ? get_sub_field('price') : false; | |
$price_sale = get_sub_field('price_sale') ? get_sub_field('price_sale') : false; | |
$default_package = get_sub_field('default_package'); | |
if ($i === 0) { | |
$product_price = $price; | |
$product_price_sale = false; | |
if ($price_sale) { | |
$product_price_sale = $price_sale ; | |
} | |
} | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item">'; | |
echo $price; | |
echo '</span>'; | |
echo '<span class="pack-items--item">'; | |
if ($price_sale) { | |
if ($price_sale >= $price) { | |
echo '<span style="color: red;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} else { | |
echo '<span style="color: #dde3e7;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} | |
} | |
echo '</span>'; | |
echo '<span class="pack-items--item">'; | |
if ($default_package) { | |
if ($default_counter === 0) { | |
$product_price = $price; | |
$product_price_sale = false; | |
if ($price_sale) { | |
$product_price_sale = $price_sale; | |
} | |
echo '<span>'; | |
echo 'Default'; | |
echo ' (' . $default_counter . ')'; | |
echo '</span>'; | |
} | |
if ($default_counter >= 1) { | |
echo '<span style="color: red;">'; | |
update_sub_field('default_package', 0, get_the_ID()); | |
echo 'Default'; | |
echo ' (' . $default_counter . ')'; | |
echo '</span>'; | |
} | |
$default_counter++; | |
} | |
echo '</span>'; | |
echo '</span>'; | |
$i++; | |
endwhile; | |
endif; | |
if( have_rows('dosage_option') ): | |
$i = 0; | |
$default_counter = 0; | |
$product_price = false; | |
$product_price_sale = false; | |
while ( have_rows('dosage_option') ) : the_row(); | |
/* | |
$array_random_title = ['Cap', 'Beef', 'Tablet', 'Fish', 'Caplets', 'Chewables', 'Tube', 'Tub', 'Sachets', 'Inhalations', 'Suspension', 'Bottle']; | |
$random_item = $array_random_title[array_rand($array_random_title)]; | |
if ($random_item == 'Cap') { | |
$random_subtitle_start = 5; | |
$random_subtitle_doze = 'mg'; | |
} else if ($random_item == 'Beef') { | |
$random_subtitle_start = 5; | |
$random_subtitle_doze = 'kg'; | |
} else if ($random_item == 'Tablet') { | |
$random_subtitle_start = 5; | |
$random_subtitle_doze = 'mg'; | |
} else if ($random_item == 'Fish') { | |
$random_subtitle_start = '100'; | |
$random_subtitle_doze = 'mg'; | |
} else if ($random_item == 'Caplets') { | |
$random_subtitle_start = 30; | |
$random_subtitle_doze = 'ct'; | |
} else if ($random_item == 'Chewables') { | |
$random_subtitle_start = 5; | |
$random_subtitle_doze = 'lbs'; | |
} else if ($random_item == 'Tube') { | |
$random_subtitle_start = 2; | |
$random_subtitle_doze = 'g'; | |
} else if ($random_item == 'Tub') { | |
$random_subtitle_start = 1; | |
$random_subtitle_doze = 'lb'; | |
} else if ($random_item == 'Sachets') { | |
$random_subtitle_start = 15; | |
$random_subtitle_doze = ' Sachets'; | |
} else if ($random_item == 'Inhalations') { | |
$random_subtitle_start = 30; | |
$random_subtitle_doze = 'mcg'; | |
} else if ($random_item == 'Suspension') { | |
$random_subtitle_start = 50; | |
$random_subtitle_doze = 'mg'; | |
} else if ($random_item == 'Bottle') { | |
$random_subtitle_start = 30; | |
$random_subtitle_doze = 'ml'; | |
} | |
$random_item_name = '' . $random_item; | |
update_sub_field('dosage_variant', $random_item_name, get_the_ID()); | |
$title = get_sub_field('dosage_variant'); | |
*/ | |
if( have_rows('qty_and_cost_variants_for_this_dose') ): | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item pack-items--title">Dosage</span>'; | |
echo '</span>'; | |
while( have_rows('qty_and_cost_variants_for_this_dose') ): the_row(); | |
/* | |
$item_variant = $random_subtitle_start . '' . $random_subtitle_doze; | |
update_sub_field('type', $item_variant, get_the_ID()); | |
$random_subtitle_start = $random_subtitle_start + $random_subtitle_start; | |
$sub_title = get_sub_field('type'); | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item pack-items--title">' . $title . ' - '. $sub_title .'</span>'; | |
echo '</span>'; | |
*/ | |
$price = get_sub_field('price') ? get_sub_field('price') : false; | |
$price_sale = get_sub_field('price_sale') ? get_sub_field('price_sale') : false; | |
$default_package = get_sub_field('default_package'); | |
if ($i === 0) { | |
$product_price = $price; | |
$product_price_sale = false; | |
if ($price_sale) { | |
$product_price_sale = $price_sale; | |
} | |
} | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item">'; | |
echo $price; | |
echo '</span>'; | |
echo '<span class="pack-items--item">'; | |
if ($price_sale) { | |
if ($price_sale >= $price) { | |
echo '<span style="color: red;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} else { | |
echo '<span style="color: #dde3e7;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} | |
} | |
echo '</span>'; | |
echo '<span class="pack-items--item">'; | |
if ($default_package) { | |
if ($default_counter === 0) { | |
$product_price = $price; | |
$product_price_sale = false; | |
if ($price_sale) { | |
$product_price_sale = $price_sale; | |
} | |
echo '<span>'; | |
echo 'Default'; | |
echo ' (' . $default_counter . ')'; | |
echo '</span>'; | |
} | |
if ($default_counter >= 1) { | |
echo '<span style="color: red;">'; | |
update_sub_field('default_package', 0, get_the_ID()); | |
echo 'Default'; | |
echo ' (' . $default_counter . ')'; | |
echo '</span>'; | |
} | |
$default_counter++; | |
} | |
echo '</span>'; | |
echo '</span>'; | |
$i++; | |
endwhile; | |
endif; | |
endwhile; | |
endif; | |
echo '</td>'; | |
echo '<td>'; | |
update_field('price', $product_price, get_the_ID()); | |
update_field('price_sale', false, get_the_ID()); | |
if ($product_price_sale) { | |
update_field('price', $product_price, get_the_ID()); | |
update_field('price_sale', $product_price_sale, get_the_ID()); | |
} | |
$price = get_field('price') ? get_field('price') : false; | |
$price_sale = get_field('price_sale') ? get_field('price_sale') : false; | |
echo $product_price; | |
echo '<br>'; | |
echo '<strong>' . $price . '</strong>'; | |
echo '<br>'; | |
echo $product_price_sale; | |
echo '<br>'; | |
echo '<strong>' . $price_sale . '</strong>'; | |
echo '</td>'; | |
echo '</tr>'; | |
endwhile; // end loop | |
endif; | |
echo '</table>'; | |
// */ | |
?> |
This file contains hidden or 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
<style> | |
.section-article table { | |
width: 100%; | |
max-width: 100%; | |
table-layout:fixed; | |
} | |
.pack-items { | |
display: flex; | |
flex-direction: row; | |
flex-wrap: wrap; | |
justify-content: space-between; | |
align-content: stretch; | |
align-items: flex-start; | |
padding-top: 5px; | |
padding-bottom: 5px; | |
} | |
.pack-items--title { | |
width: 100% !important; | |
margin-bottom: 5px; | |
padding-bottom: 5px; | |
font-size: 80% !important; | |
border-bottom: 1px dashed rgba(199, 97, 97, 0.4); | |
} | |
.pack-items--item { | |
width: 33%; | |
display: block; | |
text-align: center; | |
} | |
th:nth-child(1), | |
td:nth-child(1) { | |
width: 10% !important; | |
} | |
th:nth-child(2), | |
td:nth-child(2), | |
th:nth-child(3), | |
td:nth-child(3) { | |
width: 5% !important; | |
} | |
th:nth-child(4), | |
td:nth-child(4), | |
th:nth-child(5), | |
td:nth-child(5) { | |
width: 40% !important; | |
} | |
th:nth-child(6), | |
td:nth-child(6) { | |
width: 5% !important; | |
} | |
tr:nth-child(even) {background: #CCC} | |
tr:nth-child(odd) {background: #FFF} | |
</style> | |
<?php | |
function rand_float($st_num=0,$end_num=1,$mul=1000000) { | |
if ($st_num>$end_num) return false; | |
return mt_rand($st_num*$mul,$end_num*$mul)/$mul; | |
} | |
$query_args = array( | |
'post_type' => 'product', | |
'post_status' => 'publish', | |
'posts_per_page' => 150, | |
'paged' => (get_query_var('paged') ? get_query_var('paged') : 1), | |
'ignore_sticky_posts' => true, | |
'order' => 'ASC', | |
'orderby' => 'title', | |
); | |
$the_query = new WP_Query( $query_args ); | |
echo '<table>'; | |
echo '<tr>'; | |
echo '<th class="col-1">'; | |
echo 'Title'; | |
echo '</th>'; | |
echo '<th class="col-2">'; | |
echo 'Pricing Old'; | |
echo '</th>'; | |
echo '<th class="col-3">'; | |
echo 'Pricing New'; | |
echo '</th>'; | |
echo '<th class="col-4">'; | |
echo 'Items'; | |
echo '</th>'; | |
echo '<th class="col-5">'; | |
echo 'Updated'; | |
echo '</th>'; | |
echo '<th class="col-6">'; | |
echo 'New Pricing'; | |
echo '</th>'; | |
echo '</tr>'; | |
if ( $the_query->have_posts() ) : | |
while ( $the_query->have_posts() ) : $the_query->the_post(); // start loop | |
echo '<tr>'; | |
$price = get_field('price'); | |
$price_sale = get_field('price_sale'); | |
$sale_in_percentage = get_field('sale_in_percentage'); | |
echo '<td>'; | |
the_title(); | |
echo '</td>'; | |
echo '<td>'; | |
echo $price; | |
echo '<br>'; | |
echo $price_sale; | |
echo '<br>'; | |
if ($sale_in_percentage) { | |
echo '<strong>%</strong> '; | |
echo $sale_in_percentage; | |
} | |
echo '</td>'; | |
echo '<td>'; | |
$price = get_field('price'); | |
$price_sale = get_field('price_sale'); | |
echo $price; | |
echo '<br>'; | |
echo '<span>'; | |
if ($price_sale) { | |
if ($price_sale >= $price) { | |
echo '<span style="color: red;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} else { | |
echo '<span>'; | |
echo $price_sale; | |
echo '</span>'; | |
} | |
} | |
echo '</span>'; | |
echo '<br>'; | |
if ($sale_in_percentage) { | |
echo '<strong>%</strong> '; | |
echo $sale_in_percentage; | |
} | |
echo '</td>'; | |
echo '<td>'; | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item">Price</span>'; | |
echo '<span class="pack-items--item">Sale</span>'; | |
echo '<span class="pack-items--item"> * </span>'; | |
echo '</span>'; | |
if( have_rows('item_packages_and_quantity_variants') ): | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item pack-items--title">Standart</span>'; | |
echo '</span>'; | |
$default_counter = 0; | |
while ( have_rows('item_packages_and_quantity_variants') ) : the_row(); | |
$price = get_sub_field('price'); | |
$price_sale = strlen(get_sub_field('price_sale')) > 0 ? get_sub_field('price_sale') : false; | |
$default_package = get_sub_field('default_package'); | |
$temp_new_price = ''; | |
$temp_new_sale = false; | |
$is_a_float = (bool)random_int(0, 1); | |
$is_have_sale = (bool)random_int(0, 1); | |
$is_default = (bool)random_int(0, 1); | |
$price_new = rand_float(0.1, 600, 1000000); | |
$price_new = abs($price_new); | |
$sale_in_percent = rand(1, 15); | |
$sale_in_percent = abs($sale_in_percent); | |
$sale_in_numbers = $price_new / 100 * $sale_in_percent; | |
$price_sale_new = $price_new - $sale_in_numbers; | |
if ($is_a_float) { | |
$price_new = number_format($price_new, 2); | |
$price_sale_new = number_format($price_sale_new, 2); | |
} else { | |
$price_new = number_format($price_new, 0); | |
$price_sale_new = number_format($price_sale_new, 0); | |
} | |
$price_new = strval( $price_new ); | |
$price_sale_new = strval( $price_sale_new ); | |
update_sub_field('price', $price_new, get_the_ID()); | |
update_sub_field('price_sale', false, get_the_ID()); | |
if ($is_have_sale) { | |
update_sub_field('price_sale', $price_sale_new, get_the_ID()); | |
} | |
update_sub_field('default_package', 0, get_the_ID()); | |
if ($is_default) { | |
update_sub_field('default_package', 1, get_the_ID()); | |
} | |
$price = get_sub_field('price'); | |
$price_sale = strlen(get_sub_field('price_sale')) > 0 ? get_sub_field('price_sale') : false; | |
$default_package = get_sub_field('default_package'); | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item">'; | |
echo $price; | |
echo '</span>'; | |
echo '<span class="pack-items--item">'; | |
if ($price_sale) { | |
if ($price_sale >= $price) { | |
echo '<span style="color: red;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} else { | |
echo '<span style="color: #dde3e7;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} | |
} | |
echo '</span>'; | |
echo '<span class="pack-items--item">'; | |
if ($default_package) { | |
if ($default_counter === 0) { | |
echo '<span>'; | |
echo 'Default'; | |
echo ' (' . $default_counter . ')'; | |
echo '</span>'; | |
} | |
if ($default_counter >= 1) { | |
echo '<span style="color: red;">'; | |
update_sub_field('default_package', 0, get_the_ID()); | |
echo 'Default'; | |
echo ' (' . $default_counter . ')'; | |
echo '</span>'; | |
} | |
$default_counter++; | |
} | |
echo '</span>'; | |
echo '</span>'; | |
endwhile; | |
endif; | |
if( have_rows('dosage_option') ): | |
$default_counter = 0; | |
while ( have_rows('dosage_option') ) : the_row(); | |
if( have_rows('qty_and_cost_variants_for_this_dose') ): | |
echo '<span class="pack-items"> | |
<span class="pack-items--item pack-items--title">Dosage</span> | |
</span>'; | |
while( have_rows('qty_and_cost_variants_for_this_dose') ): the_row(); | |
$price = get_sub_field('price'); | |
$price_sale = strlen(get_sub_field('price_sale')) > 0 ? get_sub_field('price_sale') : false; | |
$default_package = get_sub_field('default_package'); | |
$temp_new_price = ''; | |
$temp_new_sale = false; | |
$is_a_float = (bool)random_int(0, 1); | |
$is_have_sale = (bool)random_int(0, 1); | |
$is_default = (bool)random_int(0, 1); | |
$price_new = rand_float(0.1, 600, 1000000); | |
$price_new = abs($price_new); | |
$sale_in_percent = rand(1, 15); | |
$sale_in_percent = abs($sale_in_percent); | |
$sale_in_numbers = $price_new / 100 * $sale_in_percent; | |
$price_sale_new = $price_new - $sale_in_numbers; | |
if ($is_a_float) { | |
$price_new = number_format($price_new, 2); | |
$price_sale_new = number_format($price_sale_new, 2); | |
} else { | |
$price_new = number_format($price_new, 0); | |
$price_sale_new = number_format($price_sale_new, 0); | |
} | |
$price_new = strval( $price_new ); | |
$price_sale_new = strval( $price_sale_new ); | |
update_sub_field('price', $price_new, get_the_ID()); | |
update_sub_field('price_sale', false, get_the_ID()); | |
if ($is_have_sale) { | |
update_sub_field('price_sale', $price_sale_new, get_the_ID()); | |
} | |
update_sub_field('default_package', 0, get_the_ID()); | |
if ($is_default) { | |
update_sub_field('default_package', 1, get_the_ID()); | |
} | |
$price = get_sub_field('price'); | |
$price_sale = strlen(get_sub_field('price_sale')) > 0 ? get_sub_field('price_sale') : false; | |
$default_package = get_sub_field('default_package'); | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item">'; | |
echo $price; | |
echo '</span>'; | |
echo '<span class="pack-items--item">'; | |
if ($price_sale) { | |
if ($price_sale >= $price) { | |
echo '<span style="color: red;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} else { | |
echo '<span style="color: #dde3e7;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} | |
} | |
echo '</span>'; | |
echo '<span class="pack-items--item">'; | |
if ($default_package) { | |
if ($default_counter === 0) { | |
echo '<span>'; | |
echo 'Default'; | |
echo ' (' . $default_counter . ')'; | |
echo '</span>'; | |
} | |
if ($default_counter >= 1) { | |
echo '<span style="color: red;">'; | |
update_sub_field('default_package', 0, get_the_ID()); | |
echo 'Default'; | |
echo ' (' . $default_counter . ')'; | |
echo '</span>'; | |
} | |
$default_counter++; | |
} | |
echo '</span>'; | |
echo '</span>'; | |
endwhile; | |
endif; | |
endwhile; | |
endif; | |
echo '</td>'; | |
echo '<td class="second result">'; | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item">Price</span>'; | |
echo '<span class="pack-items--item">Sale</span>'; | |
echo '<span class="pack-items--item"> * </span>'; | |
echo '</span>'; | |
$default_counter = 0; | |
$i = 0; | |
$product_price = false; | |
$product_price_sale = false; | |
if( have_rows('item_packages_and_quantity_variants') ): | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item pack-items--title">Standart</span>'; | |
echo '</span>'; | |
while ( have_rows('item_packages_and_quantity_variants') ) : the_row(); | |
$price = get_sub_field('price'); | |
$price_sale = strlen(get_sub_field('price_sale')) > 0 ? get_sub_field('price_sale') : false; | |
$default_package = get_sub_field('default_package'); | |
if ($i === 0) { | |
$product_price = $price; | |
$product_price_sale = false; | |
if (get_sub_field('price_sale')) { | |
$product_price_sale = get_sub_field('price_sale'); | |
} | |
} | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item">'; | |
echo $price; | |
echo '</span>'; | |
echo '<span class="pack-items--item">'; | |
if ($price_sale) { | |
if ($price_sale >= $price) { | |
echo '<span style="color: red;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} else { | |
echo '<span style="color: #dde3e7;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} | |
} | |
echo '</span>'; | |
echo '<span class="pack-items--item">'; | |
if ($default_package) { | |
if ($default_counter === 0) { | |
$product_price = $price; | |
$product_price_sale = false; | |
if (get_sub_field('price_sale')) { | |
$product_price_sale = get_sub_field('price_sale'); | |
} | |
echo '<span>'; | |
echo 'Default'; | |
echo ' (' . $default_counter . ')'; | |
echo '</span>'; | |
} | |
if ($default_counter >= 1) { | |
echo '<span style="color: red;">'; | |
update_sub_field('default_package', 0, get_the_ID()); | |
echo 'Default'; | |
echo ' (' . $default_counter . ')'; | |
echo '</span>'; | |
} | |
$default_counter++; | |
} | |
echo '</span>'; | |
echo '</span>'; | |
$i++; | |
endwhile; | |
endif; | |
if( have_rows('dosage_option') ): | |
$i = 0; | |
$default_counter = 0; | |
$product_price = false; | |
$product_price_sale = false; | |
while ( have_rows('dosage_option') ) : the_row(); | |
if( have_rows('qty_and_cost_variants_for_this_dose') ): | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item pack-items--title">Dosage</span>'; | |
echo '</span>'; | |
while( have_rows('qty_and_cost_variants_for_this_dose') ): the_row(); | |
$price = get_sub_field('price'); | |
$price_sale = strlen(get_sub_field('price_sale')) > 0 ? get_sub_field('price_sale') : false; | |
$default_package = get_sub_field('default_package'); | |
if ($i === 0) { | |
$product_price = $price; | |
$product_price_sale = false; | |
if (get_sub_field('price_sale')) { | |
$product_price_sale = get_sub_field('price_sale'); | |
} | |
} | |
echo '<span class="pack-items">'; | |
echo '<span class="pack-items--item">'; | |
echo $price; | |
echo '</span>'; | |
echo '<span class="pack-items--item">'; | |
if ($price_sale) { | |
if ($price_sale >= $price) { | |
echo '<span style="color: red;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} else { | |
echo '<span style="color: #dde3e7;">'; | |
echo $price_sale; | |
echo '</span>'; | |
} | |
} | |
echo '</span>'; | |
echo '<span class="pack-items--item">'; | |
if ($default_package) { | |
if ($default_counter === 0) { | |
$product_price = $price; | |
$product_price_sale = false; | |
if (get_sub_field('price_sale')) { | |
$product_price_sale = get_sub_field('price_sale'); | |
} | |
echo '<span>'; | |
echo 'Default'; | |
echo ' (' . $default_counter . ')'; | |
echo '</span>'; | |
} | |
if ($default_counter >= 1) { | |
echo '<span style="color: red;">'; | |
update_sub_field('default_package', 0, get_the_ID()); | |
echo 'Default'; | |
echo ' (' . $default_counter . ')'; | |
echo '</span>'; | |
} | |
$default_counter++; | |
} | |
echo '</span>'; | |
echo '</span>'; | |
$i++; | |
endwhile; | |
endif; | |
endwhile; | |
endif; | |
echo '</td>'; | |
echo '<td>'; | |
update_field('price', $product_price, get_the_ID()); | |
update_field('price_sale', false, get_the_ID()); | |
if ($product_price_sale) { | |
update_field('price', $product_price, get_the_ID()); | |
update_field('price_sale', $product_price_sale, get_the_ID()); | |
} | |
echo $product_price; | |
echo '<br>'; | |
echo $product_price_sale; | |
echo '</td>'; | |
echo '</tr>'; | |
endwhile; // end loop | |
endif; | |
echo '</table>'; | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment