Yoan De Macedo [ Web & Minimalism ]

Payment by installments each week with Stripeseveral

Today, Stripeseveral plugin is able to split a payment in X installments. Charges are executed each month.
If you want to charge each week instead of each month, it's not possible with the native plugin. But ... there is a solution.

There are usefull hooks in the plugin and with a few lines of code, it's easy to switch from months to weeks.
Just add this in your functions.php file and enjoy.

add_filter('stripeseveral_aftercheckoutreview', 'changeAfterCheckoutReview', 10, 3);
add_filter('stripeseveral_beforepaymentbox', 'changeInstallmentPlanTable', 10, 2);
add_filter('stripeseveral_afterpayment', 'installmentsByWeeks', 10);

function changeAfterCheckoutReview($msg, $total1, $total2){
    $msg = '<b>' . __('Your order contains products payable in several installments', 'stripeseveral') . '.<br />'
            . __('Total order is', 'stripeseveral') . ' ' . number_format_i18n($total1, 2)
            . ' ' . get_woocommerce_currency_symbol() . ' ' . __('but the first charge will be', 'stripeseveral') . ' ' . number_format_i18n($total2, 2) . ' ' . get_woocommerce_currency_symbol() . '</b> <br /><br />';

    $msg .= '<b>' . __('Your credit card will be stored with all the necessary security by our service provider Stripe in order to be able to charge you the following weeks', 'stripeseveral') . '.</b>';

    return $msg;

}

function changeInstallmentPlanTable($msg, $payment){

    for($i = 1; $i < count($payment); $i++)
        $payment[$i]['date'] = date('Y-m-d', strtotime('+' . $i . ' week'));

    $msg = '<table class="td stripeseveral-customeraccount-order-installement-table " cellspacing="0" cellpadding="6" border="1">
                 <thead><tr><th class="td stripeseveral-customeraccount-order-installement-th" scope="col">' . __('Date', 'stripeseveral') . '</th>
                        <th class="td stripeseveral-customeraccount-order-installement-th" scope="col">' . __('Amount', 'stripeseveral') . '</th>
                                        </tr></thead>
                <tbody>';

    for($i = 0; $i < count($payment); $i++){

            $msg .= '<tr class="order_item"><td class="td stripeseveral-customeraccount-order-installement-tr">' .  $payment[$i]['date']. '</td>
            <td class="td stripeseveral-customeraccount-order-installement-td">' . number_format_i18n($payment[$i]['charge'], 2) . ' ' . get_woocommerce_currency_symbol() . '</td>
            </tr>';
    }

    $msg .= '</tbody></table>'; 

    return $msg;
}

function installmentsByWeeks($date){
    for($i = 0; $i < count($date); $i++){
            for($j = 1; $j < count($date[$i]); $j ++){
                    $date[$i][$j]['date'] = date('Y-m-d', strtotime('+' . $j . ' week'));
            }

    }

    return $date;
}

Blog posts | Who am I ? | mail@yoandm.com

I share information with you.
Signup here. I hate SPAM.
Legal notices | Powered by Grav