function initial_product_data ( $post_id ) {
// lets get out of here if this is not a new product
if ( \'product\' != $_POST[\'post_type\'] )
return;
// make sure the post isn\'t automagically featured
// WTF WooCommerce??!!
update_post_meta( $post_id, \'_featured\', \'no\' );
// automatically set the swatch
update_post_meta( $post_id, \'_swatch_type\', \'pickers\' );
update_post_meta( $post_id, \'_swatch_type_options\', unserialize(\'a:1:{s:7:"pa_size";a:4:{s:4:"type";s:12:"term_options";s:6:"layout";s:7:"default";s:4:"size";s:19:"swatches_image_size";s:10:"attributes";a:3:{s:7:"x-large";a:3:{s:4:"type";s:5:"color";s:5:"color";s:7:"#FFFFFF";s:5:"image";s:1:"0";}s:23:"x-large-toplarge-bottom";a:3:{s:4:"type";s:5:"color";s:5:"color";s:7:"#FFFFFF";s:5:"image";s:1:"0";}s:23:"x-small-topsmall-bottom";a:3:{s:4:"type";s:5:"color";s:5:"color";s:7:"#FFFFFF";s:5:"image";s:1:"0";}}}}\') );
}
add_action( \'wp_insert_post\', \'initial_product_data\' );
代码运行良好,几乎完成了它应该做的事情。但是,似乎每次保存产品时都会触发,用户无法更改初始产品创建时设置的值。
有什么建议吗?或者这是WordPress的bug?