有没有人能帮我写一下下面的代码?仅当产品名称包含字符串"Fiat"时,我才try 向新创建的产品添加自定义采购备注.
add_action( 'transition_post_status', 'bbloomer_add_custom_meta_on_publish_product', 9999, 3 );
function bbloomer_add_custom_meta_on_publish_product( $new_status, $old_status, $post ) {
$product = wc_get_product( id );
$prod_name = $product->get_title();
$string_to_find = 'Fiat';
if ( 'product' === $post->post_type && 'publish' === $new_status && 'publish' !== $old_status && strpos( strtolower($product_name), $string_to_find ) === true ) {
update_post_meta( $post->ID, '_purchase_note', 'This is my Fiat text' );
}}