Skip to content

Instantly share code, notes, and snippets.

@klsdfr
Created August 29, 2018 15:19
Show Gist options
  • Select an option

  • Save klsdfr/6fbc5ece04f2a6eb52fba06c9c39490f to your computer and use it in GitHub Desktop.

Select an option

Save klsdfr/6fbc5ece04f2a6eb52fba06c9c39490f to your computer and use it in GitHub Desktop.

Revisions

  1. klsdfr created this gist Aug 29, 2018.
    16 changes: 16 additions & 0 deletions woocommerce-discount-on-content-count.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    // Hook before calculate fees
    add_action('woocommerce_cart_calculate_fees' , 'add_custom_fees');

    /**
    * Add custom fee if more than three article
    * @param WC_Cart $cart
    */
    function add_custom_fees( WC_Cart $cart ){
    if( $cart->cart_contents_count < 3 ){
    return;
    }

    // Calculate the amount to reduce
    $discount = $cart->subtotal * 0.1;
    $cart->add_fee( 'You have more than 3 items in your cart, a 10% discount has been added.', -$discount);
    }