Viewing 4 replies - 1 through 4 (of 4 total)
  • e

    (@xaviesteve)

    This is a much needed feature, right now users don’t realise bulk discounts exist until they go to the Checkout page.

    Add the below function to your functions.php for your theme. It will return a 2d associative array in the form of…

    Array ( [0] => Array ( [quantity] => 0 [discount] => 0 ) [1] => Array ( [quantity] => 3 [discount] => 60 ) [2] => Array ( [quantity] => 4 [discount] => 160 ) [3] => Array ( [quantity] => 5 [discount] => 300 ) [4] => Array ( [quantity] => 6 [discount] => 420 ) )

    This is all the discounts associated with a product. You can call this function in your functions.php.

    Even better would be to add it to the plugin as a static function so it can be called from any templete file.

    DEVELOPER..CAN YOU PLEASE ADD THIS TO THE PLUGIN IN THE NEXT RELEASE.

    I am not yelling. ??

    function get_product_discount( $product_id ) {
    global $woocommerce;
    $quantity_discount = array( array(‘quantity’=>0.0, ‘discount’=>0.0) );

    /* Find the appropriate discount coefficient by looping through up to the five discount settings */
    for ( $i = 1; $i <= 5; $i++ ) {
    if ( get_post_meta( $product_id, “_bulkdiscount_quantity_$i”, true ) ) {
    $q = get_post_meta( $product_id, “_bulkdiscount_quantity_$i”, true );

    if ( get_option( ‘woocommerce_t4m_discount_type’, ” ) == ‘flat’ ) {
    $d = get_post_meta( $product_id, “_bulkdiscount_discount_flat_$i”, true ) ? max( 0, get_post_meta( $product_id, “_bulkdiscount_discount_flat_$i”, true ) ): 0.0;
    } else {
    $d = get_post_meta( $product_id, “_bulkdiscount_discount_$i”, true ) ? min( 1.0, max( 0, ( 100.0 – round( get_post_meta( $product_id, “_bulkdiscount_discount_$i”, true ), 2 ) ) / 100.0 ) ) : 0.0;
    }
    array_push($quantity_discount, array(‘quantity’=>$q, ‘discount’=>$d));
    }
    }

    return $quantity_discount;
    }

    manyhands… or anyone who thinks they can help,

    i added your functions from above to get the “pricing table view” on the product page and now i can not get back into my site. i think i totally crashed it.

    i entered your function into the functions.php for my storefront theme:
    Array ( [0] => Array ( [quantity] => 0 [discount] => 0 ) [1] => Array ( [quantity] => 3 [discount] => 60 ) [2] => Array ( [quantity] => 4 [discount] => 160 ) [3] => Array ( [quantity] => 5 [discount] => 300 ) [4] => Array ( [quantity] => 6 [discount] => 420 ) )

    now, i get the following error anytime i try to get back into wp-admin of my site:
    Parse error: syntax error, unexpected ‘[‘, expecting ‘)’ in /home4/waa5dw0aar34/public_html/wp-content/themes/storefront/functions.php on line 30

    i would just go back in and remove this funtion… but i can’t get access.

    please help! thanks to anyone who can help!

    longvitr

    The code you posted wasnt the function, it was the expected output.

    You can regain access by logging into your Hosting account File manager and removing the code from functions.php

    Though you may have fixed this in the last 3 months.. Good luck!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Table Pricing on the product page’ is closed to new replies.