• Resolved lucascilinguo

    (@lucascilinguo)


    Hi I have a need, I would like to add a code to make some calculations that I would like to get the variation out next to it and not below, I managed to put it below, however when I change the management of the radio button it doesn’t work, what I would like is as it comes out on this site

    https://tipiliano.com/shop/caffe/cialda-ese-44/borbone-cialda-carta-miscela-rossa/

    the radio button code of the variation swatches plugin is

    return sprintf( ‘

                    <li %1$s class=”variable-item %2$s-variable-item %2$s-variable-item-%3$s %4$s” title=”%5$s” data-title=”%5$s” data-value=”%6$s” role=”radio” tabindex=”0″>

                    <div class=”variable-item-contents”>

                   ‘, wc_implode_html_attributes( $html_attributes ), esc_attr( $attribute_type ), esc_attr( $option_slug ), esc_attr( $css_class ), esc_html( $option_name ), esc_attr( $slug ) );

                }

    my current php function is:

    function custom_sale_price_html( $price, $product ) {
    if ( $product->is_on_sale() && is_product() ) {
    $regular_price = (float) $product->get_regular_price();
    $sale_price = (float) $product->get_sale_price();
    $percentage = round( ( $regular_price – $sale_price ) / $regular_price * 100 );

        // Ottieni la descrizione del prodotto
        $product_description = $product->get_description();
    
        // Trova la quantità dalla descrizione del prodotto (assumendo che sia nel formato "Quantità: X")
        preg_match( '/Quantità: (\d+)/', $product_description, $matches );
        $quantita_per_cialda = isset( $matches[1] ) ? intval( $matches[1] ) : 1;
    
        // Calcolo del prezzo per cialda
        $prezzo_per_cialda = $sale_price / $quantita_per_cialda;
    
         $price = '<ins> ' . wc_price( $sale_price ) . '</ins> 
         <span class="ls_test_regular-price"></span> 
        <del>' . wc_price( $regular_price ) . '</del> 
        <span class="ls_test_percentage"></span>
        <span class="onsale">' . $percentage . '%</span>
        <br>
        <span class="prezzo-per-cialda">Prezzo per cialda: ' . wc_price( $prezzo_per_cialda ) . '</span>';
    }
    return $price;

    }
    add_filter( ‘woocommerce_get_price_html’, ‘custom_sale_price_html’, 10, 2 );

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support fizanzvai

    (@fizanzvai)

    @lucascilinguo

    Thanks for reaching out to us. Can you please give me an example of what are you trying to visualize? A screenshot will help me to understand it clearly.

    Thanks

    Thread Starter lucascilinguo

    (@lucascilinguo)

    yes here is what I want add price for “cialda”

    that’s my actual result with the code that I share.

    Plugin Support fizanzvai

    (@fizanzvai)

    @lucascilinguo

    Thanks for sharing the screenshots. Unfortunately, this feature is not currently available right now.

    Thread Starter lucascilinguo

    (@lucascilinguo)

    I know the plug in have and add_filter for this result? I can use custom code.

    Plugin Support fizanzvai

    (@fizanzvai)

    @lucascilinguo

    The code you provided and the expected output is not close.

    I will suggest you hire a Woo expert regarding your customization since our plugin doesn’t offer the feature you have indicated.

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Add element near attribute value’ is closed to new replies.