Woocommerce subscription variable products message error


/ Published in: PHP
Save to your folder(s)

This function is a workaround for a bug of the subscription extension of WooCommerce.
If the subscription is set up as a variable product with monthly and yearly prices
the extension will show the wrong message, like '$10 - $120/month' instead of
'$10/month - $120/year'
Making the function general would have taken too long so I've simply hardcoded the product IDs


Copy this code and paste it in your HTML
  1. /*
  2. This function is a workaround for a bug of the subscription extension of WooCommerce.
  3. If the subscription is set up as a variable product with monthly and yearly prices
  4. the extension will show the wrong message, like '$10 - $120/month' instead of
  5. '$10/month - $120/year'
  6.  */
  7. function replace_price_string() {
  8. $first_price = WC_Subscriptions_Product::get_price('61842');
  9. $first_period = WC_Subscriptions_Product::get_period( '61842' );
  10. $second_price = WC_Subscriptions_Product::get_price('61844');
  11. $second_period = WC_Subscriptions_Product::get_period( '61844' );
  12. $subscription_string = 'From: $'.$first_price.'/'.$first_period.' to $'.$second_price.'/'.$second_period;
  13. return $subscription_string;
  14. }
  15.  
  16. add_filter('woocommerce_subscriptions_product_price_string', 'replace_price_string', '60697');

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.