Skip to content

Instantly share code, notes, and snippets.

@dsebao
Created December 8, 2020 23:56
Show Gist options
  • Select an option

  • Save dsebao/af987b1fa250a18e72b319f2a7ce1fad to your computer and use it in GitHub Desktop.

Select an option

Save dsebao/af987b1fa250a18e72b319f2a7ce1fad to your computer and use it in GitHub Desktop.

Revisions

  1. dsebao created this gist Dec 8, 2020.
    31 changes: 31 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    <?php


    add_filter('woocommerce_get_price_html', 'custom_price_message', 100, 2);
    function custom_price_message($price, $product)
    {
    //aca se podria realizar diferentes acciones dependiendo del tipo de producto, es solo de muestra
    if ($product->get_type() === 'simple') {
    }

    //ACA EMPIEZA EL SNIPPET

    $nuevoprecio = '';

    //Obtengo el precio del producto
    $price = $product->get_price();

    //Obtengo las cuotas
    $precio_en_cuotas = wc_price($price / 12); // Acá fijate si querés con decimales o redondo.

    //Comparo si hay algun descuento aplicado y si lo hay lo muestro tachado
    if($price != $product->get_regular_price()){
    $nuevoprecio .= "<del>" . wc_price($product->get_regular_price()) . "</del> ";
    }

    //Agrego las cuotas correspondientes
    $nuevoprecio .= wc_price($price) . ' <br><span class="custom-price-prefix">' . __('<b>Hasta 12 Cuotas sin interés de</b> ') . $precio_en_cuotas . '</span>';

    //retorno el snippet html resultanto
    return $nuevoprecio;
    }