You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress平台Paid Memberships Pro插件会员列表CSV导出价格格式调整:如何定位CSV内容生成位置

How to Fix Paid Memberships Pro CSV Export Price Format for French Locale

Great question! Let's break down how to adjust the price formatting in PMPro's member list CSV export without modifying core plugin files (which gets overwritten on updates).

First, you're right that admin-ajax.php is just WordPress's core AJAX handler—PMPro registers its own AJAX action for the CSV export, so we need to target that plugin-specific code.

Step 1: Locate the PMPro CSV Export Handler

The memberslist_csv AJAX action is handled by the pmpro_memberslist_csv() function, which lives in paid-memberships-pro/adminpages/memberslist.php in the plugin directory. You can confirm this by searching your plugin files for add_action('wp_ajax_memberslist_csv'—that line registers the function that generates the CSV.

Step 2: Modify Price Formatting (Best Practice: Use Filters)

PMPro includes several filters to customize CSV exports without editing core plugin code. Here's the cleanest approach:

Option 1: Use PMPro's CSV Data Filter

If your version of PMPro includes the pmpro_memberslist_csv_data filter (check the pmpro_memberslist_csv() function for this), add this code to your theme's functions.php file (or a custom plugin):

add_filter('pmpro_memberslist_csv_data', 'custom_pmpro_format_csv_prices', 10, 2);
function custom_pmpro_format_csv_prices($csv_data, $user) {
    // Format initial payment price
    if (!empty($csv_data['initial_payment'])) {
        $csv_data['initial_payment'] = number_format((float)$csv_data['initial_payment'], 2, ',', '');
    }
    // Format recurring billing amount
    if (!empty($csv_data['billing_amount'])) {
        $csv_data['billing_amount'] = number_format((float)$csv_data['billing_amount'], 2, ',', '');
    }
    // Add any other price fields here (e.g., setup fee)
    return $csv_data;
}

This directly targets the price fields in the CSV data array and formats them to the French-style X,XX format using PHP's number_format() function.

Option 2: Capture and Modify CSV Output (If No Filter Exists)

If the filter above isn't available in your PMPro version, use output buffering to capture the generated CSV content, adjust the price formatting, then output the modified version. Add this to your theme's functions.php:

// Hook into the AJAX action before PMPro runs its handler
add_action('wp_ajax_memberslist_csv', 'custom_pmpro_csv_fix_price_format', 1);
function custom_pmpro_csv_fix_price_format() {
    // Start capturing output
    ob_start();
    
    // Let PMPro generate the original CSV
    do_action('wp_ajax_memberslist_csv', 'pmpro_memberslist_csv');
    
    // Get the captured CSV content
    $csv_content = ob_get_clean();
    
    // Regex to replace prices like "120.00000000" with "120,00"
    $csv_content = preg_replace('/(\d+)\.(\d{2})\d{6}/', '$1,$2', $csv_content);
    
    // Output the modified CSV
    echo $csv_content;
    
    // Exit to prevent extra WordPress output
    exit;
}

Step 3: Avoid Direct Plugin Edits

Never edit the core PMPro files directly—any changes you make will be lost when the plugin updates. Using a theme's functions.php or a custom plugin ensures your modifications persist through updates.

内容的提问来源于stack exchange,提问作者user3102556

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 22:38:10