自定义 WooCommerce Subscribe All The Things 插件生成的“订阅选项”字符串

Customize “subsription option” string generated by WooCommerce Subscribe All The Things plugin

我正在尝试在 subscription-price">

之后通过 functions.php 添加文本

我可以通过直接代码编辑来完成此操作,但需要帮助才能通过 functions.php 应用过滤器而不更改原始文件。

$option_description = apply_filters( 'wcsatt_single_product_subscription_option_description', '<span class="' . $option_price_class . ' subscription-price">Text Here' . $sub_price_html . '</span>', $sub_price_html, $has_price_filter, false === $force_subscription, $product, $subscription_scheme );

        $option = array(
            'class'       => 'subscription-option',
            'value'       => $scheme_key,
            'selected'    => $default_subscription_scheme_option_value === $scheme_key,
            'description' => $option_description,
            'data'        => $option_data
        );

类似的东西

add_filter( 'wcsatt_single_product_subscription_option_description', 'add_custom_text_to_subscription_option');

function add_custom_text_to_subscription_option( $product) {

}

这应该足够了,基本上您分配给 $option_descreption 变量的任何内容都会显示出来

根据您的需要替换此答案中的 Your new text

function filter_wcsatt_single_product_subscription_option_description( $option_description, $sub_price_html, $has_price_filter, $force_subscription, $product, $subscription_scheme ) {
    // Class
    $option_price_class = 'subscription-option';
    
    // New description
    $option_description = '<span class="' . $option_price_class . ' subscription-price">Your new Text ' . $sub_price_html . '</span>';
    
    return $option_description;
}
add_filter( 'wcsatt_single_product_subscription_option_description', 'filter_wcsatt_single_product_subscription_option_description', 10, 6 );