Add element near attribute value
-
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]
The topic ‘Add element near attribute value’ is closed to new replies.

