-
-
Save lukecav/7c61fbd706659f947090c36c9d39dbab to your computer and use it in GitHub Desktop.
Hide WooCommerce subscriptions text (in product and cart pages) from products with a set Price but no Subscription Fee
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Define which products we should hide the subscription text for | |
| function should_hide_subscription_text($product){ | |
| $is_subscription = (get_class($product) == 'WC_Product_Variable_Subscription'); | |
| $has_price = (intval($product->subscription_price)>0); | |
| $has_fee = (intval($product->subscription_sign_up_fee)>0); | |
| if($is_subscription && $has_price && !$has_fee){ | |
| return true; | |
| } else { | |
| return false; | |
| } | |
| } | |
| function custom_subscriptions_product_price_string( $pricestring, $product, $include ) { | |
| global $product; | |
| if ( should_hide_subscription_text($product) ) { | |
| $pricestring = str_replace( '<span class="amount">$0.00</span>', '<span class="amount">$'.$product->subscription_price.'</span>', $pricestring ); | |
| $pricestring = str_replace( 'for 1 month', '', $pricestring ); | |
| $pricestring = str_replace( 'and a', '', $pricestring ); | |
| $pricestring = str_replace( 'sign-up fee', '', $pricestring ); | |
| $pricestring = str_replace( 'month for', '', $pricestring ); | |
| $pricestring = str_replace( ' / ', '', $pricestring ); | |
| $pricestring = str_replace( 'Free!', '', $pricestring ); | |
| $pricestring = str_replace( ' months ', ' months for ', $pricestring ); | |
| } | |
| return $pricestring; | |
| } | |
| add_filter( 'woocommerce_subscriptions_product_price_string', 'custom_subscriptions_product_price_string' ); | |
| // Remove bad subscription stuff from cart | |
| function wc_subscriptions_custom_price_string( $pricestring ) { | |
| $pricestring = str_replace( '<span class="amount">$0.00</span>', '', $pricestring ); | |
| $pricestring = str_replace( '/ month for ', '', $pricestring ); | |
| $pricestring = str_replace( ' and a ', ' for ', $pricestring ); | |
| $pricestring = str_replace( ' sign-up fee', '', $pricestring ); | |
| return $pricestring; | |
| } | |
| add_filter( 'woocommerce_subscriptions_product_price_string', 'wc_subscriptions_custom_price_string' ); | |
| add_filter( 'woocommerce_subscription_price_string', 'wc_subscriptions_custom_price_string' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment