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

如何在WordPress中设置可编辑基准价,自动生成±0.15的会员专属价

Solution for Auto-Updating Member Prices from a Weekly Base Price

Hey Ivan, great question! Since you're not super comfortable with advanced WordPress tweaks, let's focus on simple, maintainable solutions that let you update just one base price each Monday, with all other prices adjusting automatically. Here are two approaches tailored to your skill level:


Option 1: Use Advanced Custom Fields (ACF) + Shortcodes (Beginner-Friendly)

This is the easiest method because ACF gives you a user-friendly interface to set your base price, and shortcodes let you display calculated prices on each member page.

Step 1: Install & Set Up ACF

  1. Install the free Advanced Custom Fields plugin from your WordPress dashboard's plugin repository.
  2. Go to Custom Fields > Add New in your WP admin panel.
  3. Create a field group named something like "Price Settings".
  4. Add a Number Field (enable decimal support) with a label like "Weekly Base Price" and field name weekly_base_price.
  5. Under Location Rules, set it to show on a dedicated "Price Settings" page (create a hidden page only you can access) or attach it to the WordPress Settings menu (ACF has an option for this under "Location" > "Options Page").

Step 2: Add the Shortcode to Your Theme

Add this code to your child theme's functions.php file (always use a child theme to avoid losing changes when updating your main theme):

function calculate_member_price($atts) {
    // Pull base price from ACF (use 'option' if you set it on an options page, or the page ID if using a specific page)
    $base_price = get_field('weekly_base_price', 'option');
    
    // Set default adjustment to 0 if no parameter is passed
    $atts = shortcode_atts(
        array(
            'adjust' => 0,
        ),
        $atts,
        'calculated_price'
    );
    
    // Calculate final price and format to 2 decimal places
    $final_price = $base_price + floatval($atts['adjust']);
    return number_format($final_price, 2);
}
add_shortcode('calculated_price', 'calculate_member_price');

Step 3: Use the Shortcode on Member Pages

  • For your base price page (e.g., the one showing 14.55, 14.70, etc.), insert: [calculated_price adjust="0"]
  • For pages needing a +0.15 adjustment: [calculated_price adjust="0.15"]
  • For pages needing a -0.15 adjustment: [calculated_price adjust="-0.15"]

Step 4: Update Weekly

Each Monday, just navigate to your ACF settings page (or hidden "Price Settings" page) and update the "Weekly Base Price" value. All pages using the shortcode will automatically reflect the updated calculated prices.


Option 2: Pure Code (No Plugins)

If you prefer avoiding plugins, you can add a custom settings page to your dashboard to store the base price, then use the same shortcode logic.

Step 1: Add Custom Settings Page

Add this code to your child theme's functions.php:

// Add custom price settings page to admin menu
function price_settings_page() {
    add_options_page(
        'Price Settings',
        'Price Settings',
        'manage_options',
        'price-settings',
        'price_settings_page_html'
    );
}
add_action('admin_menu', 'price_settings_page');

// Render the settings page UI
function price_settings_page_html() {
    if (!current_user_can('manage_options')) return;
    ?>
    <div class="wrap">
        <h1><?php echo esc_html(get_admin_page_title()); ?></h1>
        <form action="options.php" method="post">
            <?php
            settings_fields('price_settings_group');
            do_settings_sections('price-settings');
            submit_button('Save Base Price');
            ?>
        </form>
    </div>
    <?php
}

// Register settings and fields
function price_settings_init() {
    register_setting('price_settings_group', 'weekly_base_price');
    
    add_settings_section(
        'price_settings_section',
        'Weekly Base Price',
        fn() => echo '<p>Enter the weekly base price here. All member prices will calculate based on this value.</p>',
        'price-settings'
    );
    
    add_settings_field(
        'weekly_base_price_field',
        'Base Price',
        function() {
            $value = get_option('weekly_base_price', 0);
            echo '<input type="number" step="0.01" name="weekly_base_price" value="' . esc_attr($value) . '" />';
        },
        'price-settings',
        'price_settings_section'
    );
}
add_action('admin_init', 'price_settings_init');

Step 2: Add the Shortcode

Use the shortcode function from Option 1, but replace the base price line with:

$base_price = get_option('weekly_base_price', 0);

Step 3: Use & Update

Insert the same shortcodes on your member pages, and each Monday go to Settings > Price Settings to update the base price.


Extra Tips

  • Hide Purchase Buttons: Use WP Members' content restriction tools to hide any add-to-cart buttons or purchase forms on member pages, since users can't buy products.
  • Test First: Create a test member account to verify that only the correct tier's prices are visible, and that updating the base price refreshes all calculated prices.
  • Backup: Always back up your theme files and database before adding custom code, just to be safe.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.13 09:20:46