Jump to content

Why does this keep looping? (New to coding)


Thatch77

Recommended Posts

Hey guys, wondering if anyone can help me with this issue. Basically i need the price per text to be next to the total price. But every time i move that piece of code into the other. It breaks the styling and echos out 7 times... Im probably missing something very simple as im new to developing but id really like to get this done. Any help would be fantastic. 

 

 

picdisc.PNG

 

Please find the code underneath. 

 

  1. 	
    /** * Format the price with a currency symbol. * * @param float $price * @param array $args (default: array()) * @return string */function wc_price( $price, $args = array() ) {    extract( apply_filters( 'wc_price_args', wp_parse_args( $args, array(        'ex_tax_label'       => false,        'currency'           => '',        'decimal_separator'  => wc_get_price_decimal_separator(),        'thousand_separator' => wc_get_price_thousand_separator(),        'decimals'           => wc_get_price_decimals(),        'price_format'       => get_woocommerce_price_format(),    ) ) ) );
        $negative        = $price < 0;    $price           = apply_filters( 'raw_woocommerce_price', floatval( $negative ? $price * -1 : $price ) );    $price           = apply_filters( 'formatted_woocommerce_price', number_format( $price, $decimals, $decimal_separator, $thousand_separator ), $price, $decimals, $decimal_separator, $thousand_separator );
        if ( apply_filters( 'woocommerce_price_trim_zeros', false ) && $decimals > 0 ) {        $price = wc_trim_zeros( $price );    }
        $formatted_price = ( $negative ? '-' : '' ) . sprintf( $price_format, '<span class="woocommerce-Price-currencySymbol">' . get_woocommerce_currency_symbol( $currency ) . '</span>', $price );    $return          = '<span class="woocommerce-Price-amount amount">' . $formatted_price . '</span>';
        if ( $ex_tax_label && wc_tax_enabled() ) {        $return .= ' <small class="woocommerce-Price-taxLabel tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';    }
        return apply_filters( 'wc_price', $return, $price, $args );}

    Thats the total price part of the code. And this is the price per part.

    //packsize
            $packsz = get_post_meta(get_the_id(),'price_breakdown',true);
            if($packsz != ''){
                echo '<p class="packSize">'.$packsz.'</p>';
            }
    

 

Link to comment
Share on other sites

Apologies mate. Only just realised how bad that printed. here it is in cleaner form , 

$formatted_price = ( $negative ? '-' : '' ) . sprintf( $price_format, '<span class="woocommerce-Price-currencySymbol">' . get_woocommerce_currency_symbol( $currency ) . '</span>', $price );
	$return          = '<span class="woocommerce-Price-amount amount">' . $formatted_price . '</span>';

	if ( $ex_tax_label && wc_tax_enabled() ) {
		$return .= ' <small class="woocommerce-Price-taxLabel tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
	}

	return apply_filters( 'wc_price', $return, $price, $args );
}

Link to comment
Share on other sites

Capture.PNG

 

Closest i have got after 2 days on it. Im praying this isnt a bloody wordpress edit in the end haha. I hope it is a php change... If i echo test from the html on the left side pic. It displays next to price. yet when i paste that price per code in. It shows underneath. Presumably as its in its own class. But i dunno...

Link to comment
Share on other sites

Sorry, bit late to this party,

 

Note. if you're using wordpress, you may want to backup before updating theme or you will have to do it all again...

 

For css style. (Not sure this is what you mean...)

@import url("style.css");

OR

...<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>...
Link to comment
Share on other sites

Ok well turns out i didnt do it correctly. Supposedly i should have done it via the hook so it changed it on all pages where price was shown (common sense i guess). Now im a little stuck editing the get_price_html to include price per label. Anyone can see where im going wrong??

add_filter( 'woocommerce_get_price_html', 'chris_price_html', 100, 2 );
function chris_price_html( $price, $product ){
$priceperlabel = 'each';
//write logic to get the perlabel here

    return str_replace( 'get_post_meta', 'get_post_id()'.$priceperlabel, $price );
}

Link to comment
Share on other sites

You need to make a new thread, with an appropriate subject title if you want to move on to a completely different problem.  I would suggestion you mention Wordpress and woo commerce in your subject as well, but certainly you need to relate these as being important to your question.  Many people scan subjects and don't read an actual thread unless they see some keywords that interest them or that they are familiar with.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.