我经历了一些类似https://ibenic.com/custom-woocommerce-product-type/的教程,以添加自己的自定义产品类型并将其显示在前端。我的目标是根据我的某些产品的值将标签自动添加到产品中。一切正常,但我无法添加标签。
add_action( 'woocommerce_process_product_meta_advanced', array( $this, 'save_advanced_settings' ) );
public function save_advanced_settings( $post_id ) {
$aname = isset( $_POST['_artist_name'] ) ? sanitize_text_field( $_POST['_artist_name'] ) : '';
update_post_meta( $post_id, '_artist_name', $aname ); //Works
//These were two of the common ways I found online to add tags
wp_set_post_terms( $post_id, $aname, 'post_tag' ); // Doesn't work
wp_set_post_tags($post_id, $aname, true); // Also Doesn't work
}
任何帮助将不胜感激,谢谢!