Last active
September 24, 2019 10:25
-
-
Save javierarcheni/47754f234f707e1dedea to your computer and use it in GitHub Desktop.
Conectar entradas o páginas de WordPress con artículos de Woocommerce
This file contains 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 | |
/* | |
* Requiere Advanced Custom Fields Plugin para WordPress | |
* http://www.advancedcustomfields.com/resources/relationship/ | |
* Query posts para el valor relación. | |
* Se usa meta_query LIKE para coincidir el ID como cadena "123" al valor de la base de datos array serializado como a:1:{i:0;s:3:"123";} | |
*/ | |
$productos = get_posts(array( | |
'post_type' => 'product', | |
'meta_query' => array( | |
array( | |
'key' =>; 'acf_gafas_marca', // nombre del campo personalizado | |
'value' =>; '"' . get_the_ID() . '"', // coincide ID como ejemplo "123" | |
'compare' => 'LIKE' | |
) | |
) | |
)); | |
<?php if( $productos ): ?> | |
<ul class="shop-items"> | |
<?php foreach( $productos as $producto ): ?> | |
<li class="shop-item"> | |
<div class="shop-item-container"> | |
<div class="shop-item-image"> | |
<a href="<?php echo get_the_permalink($gafa->ID); ?>"> | |
<?php | |
$image_alt = esc_attr( get_the_title( get_post_thumbnail_id($producto->ID) ) ); | |
$image_title = 'Comprar '. esc_attr( get_the_title($producto->ID)); | |
echo get_the_post_thumbnail( $producto->ID, 'medium', | |
array( 'class' => 'img-responsive', | |
'alt' => $image_alt, | |
'title' => $image_title) | |
); ?> | |
</a> | |
</div> | |
<p class="marca-modelo"><?php echo get_the_title($producto->ID); ?></p> | |
<?php $wooproduct = new WC_Product($producto->ID); ?> | |
<p class="precio"><span class="precio-normal"><?php echo esc_html($wooproduct->regular_price); ?>€</span> | |
<span class="precio-final"><?php echo esc_html($wooproduct->sale_price); ?>€</span></p> | |
</div> | |
</li> | |
<?php endforeach; ?> | |
</ul> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment