Created
April 10, 2023 21:32
-
-
Save Acephalia/00b84ae9e70e8cc3cf3ef096b8ea748e to your computer and use it in GitHub Desktop.
WC Name Your Price: Add Price Change To Cart & Checkout
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
| // Add Name Your Price Field on Cart page | |
| add_filter( 'woocommerce_cart_item_price', 'add_name_your_price_field_to_cart', 10, 3 ); | |
| function add_name_your_price_field_to_cart( $product_price, $cart_item, $cart_item_key ) { | |
| global $woocommerce; | |
| // Check if the Name Your Price plugin is active and if the current product supports it | |
| if ( class_exists( 'WC_Name_Your_Price' ) && WC_Name_Your_Price_Helpers::product_supports_name_your_price( $cart_item['data'] ) ) { | |
| // Add Name Your Price Field | |
| $name_your_price_input = woocommerce_name_your_price_input( $cart_item['product_id'], '', '', false ); | |
| $product_price .= $name_your_price_input; | |
| } | |
| return $product_price; | |
| } | |
| // Add Name Your Price Field on Checkout page | |
| add_filter( 'woocommerce_cart_item_price', 'add_name_your_price_field_to_checkout', 10, 3 ); | |
| function add_name_your_price_field_to_checkout( $product_price, $cart_item, $cart_item_key ) { | |
| global $woocommerce; | |
| // Check if the Name Your Price plugin is active and if the current product supports it | |
| if ( class_exists( 'WC_Name_Your_Price' ) && WC_Name_Your_Price_Helpers::product_supports_name_your_price( $cart_item['data'] ) ) { | |
| // Add Name Your Price Field | |
| $name_your_price_input = woocommerce_name_your_price_input( $cart_item['product_id'], '', '', false ); | |
| $product_price .= $name_your_price_input; | |
| } | |
| return $product_price; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment