1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Php coding help!

Discussion in 'White Hat SEO' started by ran60616, Oct 30, 2015.

  1. ran60616

    ran60616 Regular Member

    Joined:
    Jan 17, 2013
    Messages:
    219
    Likes Received:
    296
    Location:
    A place like no other!
    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
     
  2. towelfox

    towelfox Junior Member

    Joined:
    Jan 11, 2012
    Messages:
    173
    Likes Received:
    55
    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
     
    • Thanks Thanks x 1
  3. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,229
    Occupation:
    Retired
    Location:
    Old Peoples Home
    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 :)
     
    • Thanks Thanks x 1
  4. towelfox

    towelfox Junior Member

    Joined:
    Jan 11, 2012
    Messages:
    173
    Likes Received:
    55
    I prefer to call helper functions once, particularly if db queries could be involved.
     
  5. ran60616

    ran60616 Regular Member

    Joined:
    Jan 17, 2013
    Messages:
    219
    Likes Received:
    296
    Location:
    A place like no other!
    Thank you so much this worked. Thanks :)
     
  6. ran60616

    ran60616 Regular Member

    Joined:
    Jan 17, 2013
    Messages:
    219
    Likes Received:
    296
    Location:
    A place like no other!
    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 :)
     
  7. K.H.R

    K.H.R Jr. VIP Jr. VIP

    Joined:
    Dec 9, 2013
    Messages:
    3,154
    Likes Received:
    1,006
    Gender:
    Male
    Location:
    BHW
    This is the White Hat SEO forum. This post is belong to: PHP