• Resolved 8bit7

    (@8bit7)


    I want the user to pay the paypal fee when they buy points using the buycred form. I figured I could just edit the example for mycred_buycred_get_cost that is in the docs, but I copied all three examples exactly into my theme’s function.php and it breaks (no price shows up at all in the paypal popup).

    Paypal fees are 3.49% + $.49 So I figured this code below would work. But again, simply no price shows up at all in the paypal confirmation popup.

    
    /**
     * Buyer pays PayPal fees for custom point purchases
    
     */
    add_filter( 'mycred_buycred_get_cost', 'mycredpro_buycred_user_pays_fees', 10, 3 );
    function mycredpro_buycred_user_pays_fees( $cost, $type ) {
    
    	if ( $type != 'mycred_default' ) return $cost;
    
    	// paypal fees
    	$percent_fee = 3.49;
        $set_fee = .49;
    
    	// Get the percentage
    	$percent = round( ( ( $percent_fee / 100 ) * $cost ) );
    
    	// Deduct the discount amount
    	$cost = $cost + $percent + $set_fee;
    
    	return $cost;
    
    }

    Any help would be greatly appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter 8bit7

    (@8bit7)

    Also I found an error with the example code on the website.

    It has $discount_amount but is calling $discounted_amount. Also the function it called buyred instead of buycred

    Here is the fixed example code (however, note this does not solve my issue):

    /**
     * Give 10% Discount on Custom Point Purchases
     * @mycred
     * @version 1.0
     */
    add_filter( 'mycred_buycred_get_cost', 'mycredpro_buycred_volume_price_discount', 10, 3 );
    function mycredpro_buycred_volume_price_discount( $cost, $amount, $type ) {
    
    	if ( $type != 'mycred_default' ) return $cost;
    
    	// 10%
    	$discount = 10;
    
    	// Get the discount amount
    	$discount_amount = round( ( ( $discount / 100 ) * $cost ) );
    
    	// Deduct the discount amount
    	$cost = $cost - $discount_amount;
    
    	return $cost;
    
    }
    • This reply was modified 1 year, 11 months ago by 8bit7.
    Thread Starter 8bit7

    (@8bit7)

    The error file this example code (and my modification) gives is

    [14-Apr-2023 16:58:00 UTC] PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘mycredpro_buyred_volume_price_discount’ not found or invalid function name in [redacted] /wp-includes/class-wp-hook.php on line 310

    Thread Starter 8bit7

    (@8bit7)

    I fixed it. the issue was my theme Specrta. I made a basic plugin for it and it works fine. Here’s the final working function.

    function buycred_user_pays_fees( $cost, $amount, $type ) {
    
        if ( $type != 'mycred_default' ) return $cost;
    
        // paypal fees
        $percent_fee = 3.49;
        $set_fee = 0.49;
    
        // Calculate PayPal fees
        $percent = round( ( $percent_fee / 100 ) * $cost, 4);
        $total_fee = $percent + $set_fee;
    
        // Add fees to the cost
        $cost = $cost + $total_fee;
    
        // Round up the cost to the nearest cent
        $cost = ceil( $cost * 100 ) / 100;
    
        return $cost;
    }
    
    • This reply was modified 1 year, 11 months ago by 8bit7.

    Hello @8bit7 ,

    Hope you are doing well.

    Thanks for the update.

    Let me know if you have any question.

    Thanks & Regards,

    WP Experts Support Team.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘buycred – buyers pay paypal fees?’ is closed to new replies.