Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
Establezca el precio de WooCommerce según el campo personalizado y la fecha personalizada (no funciona)

Estoy trabajando en un "precio de venta" invertido como en " Future Price " para productos individuales en WooCommerce.

La idea general es establecer un precio (precio futuro) y una fecha de inicio + finalización. Luego, utilizando el filtro woocommerce_product_get_price , verifique si hoy es el mismo que el valor de "fecha de inicio del precio futuro" y, si son iguales, cambie el precio del producto.

Cuando haya pasado la fecha de finalización del precio futuro, restaure el precio del producto al precio normal.

El problema es que no recibo ningún error ni aviso ni nada por el estilo, lo que significa que estoy perdido :)

Para lograr todo esto, he creado un campo personalizado (precio futuro). También he creado los campos de fecha. Todos están guardados y actualizados.

Si alguien puede ayudarme y darme consejos / sugerencias, lo agradecería mucho. Este es mi segundo proyecto escolar (2 de 3) que vence dentro de una semana.

Este es mi código completo:

 add_filter( 'woocommerce_product_get_price', 'future_product_price', 20, 2 ); function future_product_price( $price, $product ) { if ( is_admin() ) return $price; $future_price = get_post_meta( $product->get_id(), 'future_price', true ); // future product price $future_start_date = get_post_meta( $product->get_id(), '_future_price_date_from', true ); // future product price start date $future_end_date = get_post_meta( $product->get_id(), '_future_price_date_to', true ); // future product price end date if ( ! empty( $future_price ) && ! empty( $future_start_date ) && ! empty( $future_end_date ) ) { $future_date_time = (int) strtotime( $future_start_date ); // convert $now_time = (int) strtotime("now"); // now in seconds // check if right now is the same day as the future price start date if ( $now_time == $future_start_date ) // if they are the same, set the product price to the future price $price = $future_price; } return $price; }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

cambie "add_filter woocommerce_product_get_price" a "woocommerce_get_price_html" para mostrar el precio real y algunos pequeños cambios en su función future_product_price:

 add_filter( 'woocommerce_get_price_html', 'future_product_price', 20, 2 ); function future_product_price( $price, $product ) { if ( is_admin() ) return $price; $future_price = get_post_meta( $product->get_id(), 'future_price', true ); // future product price $future_start_date = get_post_meta( $product->get_id(), '_future_price_date_from', true ); // future product price start date $future_end_date = get_post_meta( $product->get_id(), '_future_price_date_to', true ); // future product price end date if ( ! empty( $future_price ) && ! empty( $future_start_date ) && ! empty( $future_end_date ) ) { $future_start = (int) strtotime( $future_start_date ); // convert $future_end = (int) strtotime( $future_end_date ); // convert $now_time = (int) strtotime(date('Ym-d')); // now in seconds // check if right now is the same day as the future price start date if($future_start <= $now_time && $now_time <= $future_end) { // if they are the same, set the product price to the future price $price = $future_price; } } return $price; }

Agregue otras funciones para establecer precios futuros en un carrito o pago:

 add_action( 'woocommerce_before_calculate_totals', 'set_alter_price_cart', 20, 2 ); function set_alter_price_cart( $cart ) { if ( is_admin()) return; foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) { $product = $cart_item['data']; $price = $product->get_price(); $future_price = get_post_meta( $product->get_id(), 'future_price', true ); // future product price $future_start_date = get_post_meta( $product->get_id(), '_future_price_date_from', true ); // future product price start date $future_end_date = get_post_meta( $product->get_id(), '_future_price_date_to', true ); // future product price end date if ( ! empty( $future_price ) && ! empty( $future_start_date ) && ! empty( $future_end_date ) ) { $future_start = (int) strtotime( $future_start_date ); // convert $future_end = (int) strtotime( $future_end_date ); // convert $now_time = (int) strtotime(date('Ym-d')); // now in seconds // check if right now is the same day as the future price start date if($future_start <= $now_time && $now_time <= $future_end) { $price = $future_price; } $cart_item['data']->set_price($price); } } }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda