/*Mostrar algo si un post es de un tipo
determinado */
if (get_post_type() === 'tipo') {
//Código a mostrar
}
/**
* WP_Query
**/
$args = array(
'posts_per_page' => 4,//Cuatro resultados
'post_type' => 'recetas',
'orderby' => 'rand', //Orden aleatorio.
'tax_query' => array(//Ojo aquí array y dentro otro array
array(
'taxonomy' => 'tipo-comida',
'field' => 'slug',
'terms' => 'comida-italiana'
)
),
);
$comida = new WP_Query($args);
while ($comida->have_posts()) :
$comida->the_post();
the_title('<h1>', '</h1>');//Salida
endwhile;
wp_reset_postdata;
const plazos = 3 //Cambiar por el número de plazos
const selectores = document.querySelectorAll('.cfvsw-swatches-option')//Selectores Variaciones
const contenedorCuota = document.querySelector('#shortcode-112-74')//Localizado Shortcode
const valInicial = contenedorCuota.children[0].innerText //Valor cuota inicial
const btnReset = document.querySelector('.reset_variations')//Boton Limpiar
const contenedorPrecio = document.querySelectorAll('#-product-price-53-74')//Contenedor Precio Principal
function formateaCuota(cadena) {
let numero=cadena.toString();
let regex=/(\d*.\d{0,2})/;
numero = numero.match(regex)[0];
let partes = numero.toString().split(".");
partes[0] = partes[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".");
numero = partes.join(".");
regex = /\.(?=[^.]*$)/;
if (numero.split('.').length > 2) return numero.replace(regex, ',');
return numero
}
function tomaPrecio(){
if(contenedorPrecio[0].children[0].outerText=="")
return valInicial
precioActual = contenedorPrecio[0].children[0].children[0].children[1].outerText //Valor Precio Principal
precioActual=(precioActual.replace(".", "").replace(",", ".").replace("$", ""))*1
precioActual =formateaCuota(precioActual/plazos)
return precioActual = '$'+precioActual
}
muestraCuota = ()=>{
contenedorCuota.children[0].innerText= tomaPrecio()
}
btnReset.addEventListener('click', () =>{
contenedorCuota.children[0].innerText= valInicial
})
selectores.forEach((selector)=>{
selector.addEventListener('click', ()=>{
setTimeout(muestraCuota, 700);
})
})
/***
Crea una función que diga si el artículo vendido de woocomerce tiene envío o recogida local teniendo el id del pedido
https://chat.openai.com/share/2a678bd5-4147-480b-9fd5-e486538fed6e
**/
/***
CodeWp
**/
<?php
/**
* cwpai_check_shipping_method
* Returns whether the given order_id has a shipping method of "Local Pickup" or not
*
* @param int $order_id The ID of the order to check
* @return bool True if "Local Pickup" is the shipping method, false otherwise
*/
function cwpai_check_shipping_method($order_id) {
$order = wc_get_order($order_id); // Get the order object
$shipping_methods = $order->get_shipping_methods(); // Get an array of all shipping methods for the order
foreach ($shipping_methods as $shipping_method) { // Loop through each shipping method
if ($shipping_method->get_method_id() === 'local_pickup') { // Check if the method ID matches "local_pickup"
return true; // If so, we have local pickup and return true
}
}
return false; // If we loop through all shipping methods and don't find "local_pickup", return false
}
const plazos = 3 //Cambiar por el número de plazos
const selectores = document.querySelectorAll('.cfvsw-swatches-option')//Selectores Variaciones
const contenedor = document.querySelector('#shortcode-112-74')//Localizado Shortcode
const valInicial = contenedor.children[0].innerText //Valor cuota inicial
const btnReset = document.querySelector('.reset_variations')//Boton Limpiar
function dosDecimales(n) {
let t=n.toString();
let regex=/(\d*.\d{0,2})/;
return t.match(regex)[0];
}
function separadorMiles(x) {
let t=x.toString();
let regex=/(\d*.\d{0,2})/;
let m = t.match(regex)[0];
var parts = m.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".");
return parts.join(".");
}
function ponComa(cadena) {
let t=cadena.toString();
let regex=/(\d*.\d{0,2})/;
let m = t.match(regex)[0];
let parts = m.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".");
let num = parts.join(".");
let regex2 = /\.(?=[^.]*$)/;
if (num.split('.').length > 2){
return num.replace(regex2, ',');
}
return num
}
function tomaPrecio(){
let contenedorPrecio = document.querySelectorAll('#-product-price-53-74')//Contenedor Precio Principal
//console.log(contenedorPrecio)
if(contenedorPrecio[0].children[0].outerText=="")
return contenedor.children[0].innerText= valInicial
precioActual = contenedorPrecio[0].children[0].children[0].children[1].outerText //Valor Precio Principal
precioActual = precioActual.replace("$", "")
precioActual=precioActual.replace(".", "").replace(",", ".")
precioActual=precioActual*1
let cuota = precioActual/plazos
// cuota = dosDecimales(cuota)
//cuota = separadorMiles(cuota)
cuota =ponComa(cuota)
cuota = '$'+cuota
return contenedor.children[0].innerTex= cuota
}
muestraCuota = ()=>{
contenedor.children[0].innerText= tomaPrecio()
}
btnReset.addEventListener('click', () =>{
contenedor.children[0].innerText= valInicial
})
selectores.forEach((selector)=>{
selector.addEventListener('click', ()=>{
contenedor.children[0].innerTex=""
setTimeout(muestraCuota, 700);
})
})
<?php
$product = wc_get_product( get_the_ID ());
$variation_data = array();
if ( $product->is_type( 'variable' ) ) {
$variations = $product->get_available_variations();
foreach ( $variations as $variation ) {
$attributes = $variation['attributes'];
$image_id = $variation['image_id'];
$image_url = wp_get_attachment_image_src( $image_id, 'full' );
$image_url = $image_url[0];
$image_thumb = wp_get_attachment_image_src( $image_id, 'thumbnail' );
$image_thumb = $image_thumb[0];
$attribute_values = array_values( $attributes );
$variation_data[] = array(
'attribute_value' => $attribute_values,
'image_url' => $image_url,
'thumb_img' => $image_thumb
);
}
usort( $variation_data, function( $a, $b ) {
return $a['variation_id'] - $b['variation_id'];
});
}
$tallas ="";
?>
<section style="display:none">
<?php
for($i=0; $i<sizeof($variation_data); $i++){
$atributoTalla =$variation_data[$i]['attribute_value'][0];
$atributoColor =$variation_data[$i]['attribute_value'][1];
$varImagen =$variation_data[$i]['image_url'];
$varThumb = $variation_data[$i]['thumb_img'];
if (strpos( $tallas, $atributoTalla."," ) === false) {
$tallas .= $atributoTalla. ",";
}
echo "<p id='".$atributoTalla.$atributoColor."'data-var_imagen =".$varImagen." data-var_thumb =".$varThumb."></p>";
}
?>
<div id="data-tallas"><?php echo $tallas; ?></div>
</section>