首页 > 解决方案 > 自定义 WooCommerce 订阅所有事物插件生成的“订阅选项”字符串

问题描述

我正在尝试在functions.php之后添加文本subscription-price">

我可以通过直接代码编辑来做到这一点,但需要帮助才能在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) {

}

标签: phpwordpresswoocommercehook-woocommerce

解决方案


这应该足够了,基本上你分配给$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 );

推荐阅读