【问题标题】:Woocommerce Subscriptions Product Price StringWoocommerce 订阅产品价格字符串
【发布时间】:2018-06-17 04:24:27
【问题描述】:

我有一个可以更改订阅详情文本的功能。

function wc_subscriptions_custom_price_string( $pricestring ) {
global $product;

$products_to_change = array( 2212 );

if ( in_array( $product->id, $products_to_change ) ) {
    $pricestring = str_replace( 'on the 20th day of every 6th month', 'on the 20th November and 20th May', $pricestring );
}

return $pricestring;
}
add_filter( 'woocommerce_subscriptions_product_price_string', 'wc_subscriptions_custom_price_string' );

这很好用 - 但它不会更改购物车或迷你购物车中的文本 - 仍然显示每 6 个月第 20 天的默认文本。我如何也将它应用到购物车?

【问题讨论】:

    标签: wordpress woocommerce woocommerce-subscriptions


    【解决方案1】:

    试试这个代码,

    function wc_subscriptions_custom_price_string( $pricestring ) {
    global $product;
    
    $products_to_change = array( 2212 );
    
    if ( in_array( $product->id, $products_to_change ) ) {
        $newprice = str_replace( 'on the 20th day of every 6th month', 'on the 20th November and 20th May', $pricestring );
    }
    
    return $newprice;
    }
    add_filter( 'woocommerce_subscriptions_product_price_string', 'wc_subscriptions_custom_price_string' );
    add_filter( 'woocommerce_subscription_price_string', 'wc_subscriptions_custom_price_string' );

    希望它的工作!!

    【讨论】:

      【解决方案2】:

      我相信您需要使用一个功能来应用到产品页面(您使用global $product),并使用另一个功能来应用到购物车。

      所以你需要两个:

      //* Function for Product Pages
      function wc_subscriptions_custom_price_string( $pricestring, $product, $include ) {
      
          global $product;
      
          $products_to_change = array( 2212 );
      
          if ( in_array( $product->id, $products_to_change ) ) {
              $pricestring = str_replace( 'on the 20th day of every 6th month', 'on the 20th November and 20th May', $pricestring );
          }
      
          return $pricestring;
      
      }
      add_filter( 'woocommerce_subscriptions_product_price_string', 'wc_subscriptions_custom_price_string' );
      
      //* Function for Cart
      function wc_subscriptions_custom_price_string_cart( $pricestring ) {
      
          $pricestring = str_replace( 'on the 20th day of every 6th month', 'on the 20th November and 20th May', $pricestring );
      
          return $pricestring;
      
      }
      add_filter( 'woocommerce_subscriptions_product_price_string', 'wc_subscriptions_custom_price_string_cart' );
      add_filter( 'woocommerce_subscription_price_string', 'wc_subscriptions_custom_price_string_cart' );
      

      【讨论】:

        猜你喜欢
        • 2018-08-31
        • 2019-12-20
        • 1970-01-01
        • 1970-01-01
        • 2017-06-18
        • 2014-02-02
        • 2021-01-25
        • 1970-01-01
        • 2017-12-03
        相关资源
        最近更新 更多