Php coding help!

ran60616

Regular Member
Joined
Jan 17, 2013
Messages
219
Reaction score
298
Hey guys,

Would appreciate if someone can help me out here. Don't have much knowledge in coding!

Code:
function mm_product_parceled() {
    $product = get_product();

    if ( $product->get_price_including_tax() ) {
        $value = woocommerce_price( $product->get_price_including_tax()  / 12 );
        return $value;
    }
}

The above code works well, and it's the main function. This simply divides all the product prices into 12 equal installments in the online shopping store.

I need to figure out how to add a limit to this. I only want product that are more than $1000.00 in my store to offer 12 month installments. How can i add this to the above function for it to work correctly? ($price > 1000.00)

Thank you so much!
Ran60616
 
PHP:
function mm_product_parceled() {
    $product = get_product();
    $price = $product->get_price_including_tax();

    if ( $price > 1000 ) { 
        $value = woocommerce_price( $price / 12 );
        return $value;
    }
}

Use if ( $price >= 1000 )... For 1000 and over
 
The above can also be done in one line:

Code:
function mm_product_parceled() {
    $product = get_product();

    if ( ($product->get_price_including_tax() ) && ($product->get_price_including_tax() >= 1000)) {
        $value = woocommerce_price( $product->get_price_including_tax()  / 12 );
        return $value;
    }
}

Think thats right, just got up and haven't finished my first coffee yet :)
 
I prefer to call helper functions once, particularly if db queries could be involved.
 
PHP:
function mm_product_parceled() {
    $product = get_product();
    $price = $product->get_price_including_tax();

    if ( $price > 1000 ) { 
        $value = woocommerce_price( $price / 12 );
        return $value;
    }
}

Use if ( $price >= 1000 )... For 1000 and over

Thank you so much this worked. Thanks :)
 
The above can also be done in one line:

Code:
function mm_product_parceled() {
    $product = get_product();

    if ( ($product->get_price_including_tax() ) && ($product->get_price_including_tax() >= 1000)) {
        $value = woocommerce_price( $product->get_price_including_tax()  / 12 );
        return $value;
    }
}

Think thats right, just got up and haven't finished my first coffee yet :)

Thank you for the help :) there was an error coming up on this for the &&. towelfox solution worked. Thanks again for taking the time to help :)
 
This is the White Hat SEO forum. This post is belong to: PHP
 
Back
Top