require_once( $_SERVER['DOCUMENT_ROOT']. '/domena/wp-load.php');
if (!current_user_can('administrator')){
die('Musís byť prihlásený ako administrátor');
}
$wc_query = new WP_Query( array(
'post_type' => 'product',
//'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'vlastnost', // iba ak produkt v tejto vlastnosti má prázdnu hodnotu
'value' => '',
'compare' => '='
)
)
) );
<style>
html {
scroll-behavior: smooth;
text-align:center;
}
.produkt:hover{
background-color:#DADADA;
trasition:0.4s;
}
</style>
<body>
<h1 style="margin-top:30px;">Produkty</h1>
<div class="changing-img">
<?php if ($wc_query->have_posts()) : ?>
<?php while ($wc_query->have_posts()) :
$wc_query->the_post();
$stock = get_post_meta( get_the_ID(), '_stock', true );
$predane = (int)get_post_meta( get_the_ID(), 'total_sales', true );
$navysenie = (int)get_post_meta( get_the_ID(), 'navysenie_pozicie', true );
if ($stock >0){
update_post_meta( $id, 'skusobne_data', 100 + $navysenie + ($predane *0.01) );
}
if ($stock <1){
update_post_meta( $id, 'skusobne_data', 0 + $navysenie + ($predane * 0.01));
}
?>
<div class="produkt">
<strong><?php echo get_post_meta( get_the_ID(), 'skusobne_data', true ); ?></strong><br>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('thumbnail'); ?>
<h6><?php the_title(); ?> </h6>
</a>
<p>
<strong><?php // echo 'data: ' . get_post_meta( get_the_ID(), 'skusobne_data', true ); ?></strong>
<!-- <br> -->
<?php echo 'predane: ' . $predane ?>,
<?php echo 'sklad: ' . $stock; ?>,
<?php echo 'navysenie: ' . get_post_meta( get_the_ID(), 'navysenie_pozicie', true ); ?>
<?php $price = get_post_meta( get_the_ID(), '_price', true ); ?>
<p><?php echo wc_price( $price ); ?></p>
</p>
<hr>
</div>
<script>
window.scrollTo(0, document.body.scrollHeight);
</script>
<?php // sleep(1); ?> // spomalenie aby sa nezatazil velmi server
<?php usleep(400000); ?> // presnejsie spomalenie (0,4 s)
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<li>
<?php _e( 'No products' ); ?>
</li>
<?php endif; ?>
</div>
<h1 style="background-color:green; color:white; padding:20px 30px;">ÚSPEŠNE SPRACOVANÉ</h1>
<button id="zorad">Zoraď</button>
</body>
<script>
// zoradenie v javascripte
window.scrollTo(0, document.body.scrollHeight);
function zoradProdukty() {
var items = document.querySelectorAll('.produkt');
// magically coerce into an array first
items = Array.prototype.slice.call(items);
// Now we can sort it. Sort alphabetically
items.sort(function(a, b){
return b.textContent.localeCompare(a.textContent); // vymenit a b pre opacne zoradenie
});
// reatach the sorted elements
for(var i = 0, len = items.length; i < len; i++) {
// store the parent node so we can reatach the item
var parent = items[i].parentNode;
// detach it from wherever it is in the DOM
var detatchedItem = parent.removeChild(items[i]);
parent.appendChild(detatchedItem);
}
window.scrollTo(0, 0);
}
document.getElementById('zorad').addEventListener('click', zoradProdukty)
</script>