Hi all I've got a Woocommerce question,
I was wondering if there is a php function that rounds up all the prices to a decimal to .95 cents.
Example:
$5.66 -> $5.95
$13.23 -> $13.95
$2.54 -> $ $2.95
Thank you!
there is no built in function for it you need to make your self
`
<?php
echo myPriceFormat(12.94);
echo '<br>';
echo myPriceFormat(12.95);
echo '<br>';
echo myPriceFormat(12.96);
function myPriceFormat($no){
if( $no<(ceil($no)-0.05) ){
$no=ceil($no) - 0.05;
}
return $no;
}
?>
`
Related
I am trying to spell out WooCommerce order total amount, in my invoice.php template file can reach order total amount.
First I tried:
$total = $order->get_total();
<?php echo ( $total ); ?> -
<?php
$f = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $f->format($total); ?>
The order total displayed is 225.00 and the spell out display is: two hundred twenty-five
Edit:
I found the following solution:
<?php $number = $order->get_total() ;
$formatter = new NumberFormatter('tr', NumberFormatter::SPELLOUT);
$formatter->setTextAttribute(NumberFormatter::DEFAULT_RULESET, "%financial");
echo $formatter->format($number); ?>
But the result shows like that: two hundred twenty-five
The desired display should be: two hundred twenty-five turkish liras , zero penny.
How can i do this ?
The NumberFormatter SPELLOUT constant doesn't handle the decimals.
You can use the following custom function to display a float number amount spell out like (with the currency details):
function wc_spellout_amount( $amount, $country_code = 'tr' ) {
$formatter = new NumberFormatter($country_code, NumberFormatter::SPELLOUT);
$formatter->setTextAttribute(NumberFormatter::DEFAULT_RULESET, "%financial");
$amounts = explode('.', (string) $amount); // Separating decimals from amount
$output = $formatter->format($amounts[0]);
$output .= ' ' . _n('turkish lira', 'turkish liras', $amounts[0], 'woocommerce');
$output .= ', ' . $formatter->format($amounts[1]);
$output .= ' ' . _n('penny', 'pennies', ( $amounts[1] > 0 ? $amounts[1] : 1 ), 'woocommerce');
return $output;
}
Code goes in functions.php file of the active child theme (or active theme).
Usage: Then you will use it as follows in your code:
echo wc_spellout_amount( $order->get_total() );
Tested and works.
in a special case I need the output of wp_get_archives(); to be just raw text instead of a link. Does anyone know how to do that? I recently checked the reference but also the 'format'=>'custom' option renders a link.
Thanks in advance!
---- Edit (#vard) ----
<?php
$args2 = array(type'=>'monthly','limit'=>'','format'=>'html','before'=>'','after'=>'','show_post_count'=> false,'echo'=>1,'order'=>'DESC');
echo "<ul>";
wp_get_archives( $args );
echo "</ul>";
?>
and code from zurb.com:
add_filter( "get_archives_link", "customarchives_link");
function customarchives_link( $x ){
$url = preg_match('#(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.-]*(\?\S+)?)?)?)#i', $x, $matches);
return $matches[4] == $_SERVER['REQUEST_URI'] ? preg_replace('#<li#', '<li class="current_page_item"', $x) : $x;
}
i want my output to be like this -
echo 'codeBefore';
the_content();
echo 'codeAfter';
Problem is, one of the plugin i use inserts its code before and after the content & output i get is something like this.
echo 'codeBefore';
<plugin code>
the_content();
<plugin code>
echo 'codeAfter';
How to get my code displayed in front before any other plugin codes ?
User below Code
function slideshow_fun( $content ) {
if ( is_single() ) {
$custom_content = '[plugin_shortcode]';
$custom_content .= $content;
return $custom_content;
} else {
return $content;
}
}
add_filter( 'the_content', 'slideshow_fun' );
More detail and Credit
I have created chekboxes with ACF, now I can display the values of the checkboxes on my front end but I would like to show the associated labels to.
Here is my code :
echo "<ul>";
$profession = get_field('profession');
foreach($profession as $key => $check){
echo "<li>".$check."</li>";
};
echo "</ul>";
Thanks a lot !
try this: http://www.advancedcustomfields.com/resources/functions/get_field_object/
You can return all the field's metadata with get_field_object().
if( get_field('field_name') ):
echo '<div class="class_for_display">';
echo 'Label:'; echo'<p>' .the_field('field_name').'</p>';
echo '</div>';
endif;
i use this code in function.php of child theme
Here is what i've done so far but i just keep getting an error
<?php echo (($flag_show_product_info_model == 1 and $products_model !='') ? '<li>' . TEXT_PRODUCT_MODEL . $products_model . '</li>' : '') . "\n"; ?>
<iframe src="http://www.madisonb2b.co.uk/stockenquiry.aspx?id=B8FxKDnJ%2bIdaPT1Nw5wo4r87qHuHcCQIPZzeUE%2fI36LIFOM%2bayBi2RSXHzIJS5Hj97JNSyYL80Q%3d&code=<?php {$product_model} ?>"</iframe>
Any ideas?
Thanks,
Scott
<iframe src="http://www.madisonb2b.co.uk/stockenquiry.aspx?id=B8FxKDnJ%2bIdaPT1Nw5wo4r87qHuHcCQIPZzeUE%2fI36LIFOM%2bayBi2RSXHzIJS5Hj97JNSyYL80Q%3d&code=<?php echo $product_model ?>"</iframe>
(will work if $product_model is defined by the time you echo it, of course.
Did you want to say
echo $product_model
instead of
{$product_model}
?