Last active
April 1, 2022 20:54
-
-
Save nathaningram/4031e3a0a9a91dd01b4f16d335df29ea to your computer and use it in GitHub Desktop.
Behind the Site Code Snippets
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
| ////////// Snippets from Behind the Site March 2022 ////////// | |
| // Add to the functions.php of your active child theme or a custom functions plugin | |
| /////////////// WooCommerce Modifications /////////////// | |
| //Show FREE rather than $0.00 | |
| //Source: https://www.businessbloomer.com/woocommerce-display-free-instead-0-00-empty-price/ | |
| add_filter( 'woocommerce_get_price_html', 'bww_price_free_zero', 9999, 2 ); | |
| function bww_price_free_zero( $price, $product ) { | |
| if ( $product->is_type( 'variable' ) ) { | |
| $prices = $product->get_variation_prices( true ); | |
| $min_price = current( $prices['price'] ); | |
| if ( 0 == $min_price ) { | |
| $max_price = end( $prices['price'] ); | |
| $min_reg_price = current( $prices['regular_price'] ); | |
| $max_reg_price = end( $prices['regular_price'] ); | |
| if ( $min_price !== $max_price ) { | |
| $price = wc_format_price_range( 'FREE', $max_price ); | |
| $price .= $product->get_price_suffix(); | |
| } elseif ( $product->is_on_sale() && $min_reg_price === $max_reg_price ) { | |
| $price = wc_format_sale_price( wc_price( $max_reg_price ), 'FREE' ); | |
| $price .= $product->get_price_suffix(); | |
| } else { | |
| $price = 'FREE'; | |
| } | |
| } | |
| } elseif ( 0 == $product->get_price() ) { | |
| $price = '<span class="woocommerce-Price-amount amount">Free</span>'; | |
| } | |
| return $price; | |
| } | |
| // First Name of Logged In User Shortcode | |
| function ni_firstname() { | |
| $user = wp_get_current_user(); | |
| $firstname = $user->user_firstname; | |
| return $firstname; | |
| } | |
| add_shortcode('firstname', 'ni_firstname'); | |
| // Hide The Events Calendar Fields in Admin | |
| add_action('admin_head', 'bww_hide_tec_field_groups'); | |
| function bww_hide_tec_field_groups() { | |
| echo '<style> | |
| #wp-content-editor-tools,#wp-content-editor-container,#event_tribe_venue,#event_tribe_organizer,#event_url,#event_cost {display:none !important;} | |
| </style>'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment