functions.php
This file contains 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
/** | |
* Sets the product default price to 10. Only works once, if the price is not specified. | |
* | |
* @param int $post_id | |
* @param object $post | |
*/ | |
function set_product_default_price( $post_id, $post ) { | |
$product = wc_get_product( $post_id ); | |
$already_set = get_post_meta( $post_id, '_set_default_price', true ); | |
$price = $product->get_price(); | |
if ( 'yes' !== $already_set && empty( $price ) ) { | |
$product->set_regular_price( '10' ); | |
$product->save(); | |
update_post_meta( $post_id, '_set_default_price', 'yes' ); | |
} | |
} | |
add_action( 'woocommerce_process_product_meta', 'set_product_default_price', 999, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment