Wordpress には、「daily_cartoon」というカスタム投稿タイプの新しい投稿を追加することで、woocommerce 製品を自動的に追加できる機能があります。
これは関数のコードです:
function convert_daily_cartoon_into_product($post_id){
if( ( $_POST['post_status'] == 'publish' ) && ( $_POST['original_post_status'] != 'publish' ) ) {
// Create post object
$post = array(
'post_title' => $_POST['post_title'],
'post_type' => 'product',
'post_status' => 'publish',
'tax_input' => array( 'product_cat' => 14 )
);
// Insert the post into the database
$new_print = wp_insert_post( $post );
update_post_meta( $new_print, '_thumbnail_id', get_post_thumbnail_id( $post_id ) );
update_post_meta( $new_print, '_regular_price', 5 );
update_post_meta( $new_print, '_price', 5 );
}
}
add_action('publish_daily_cartoon', 'convert_daily_cartoon_into_product');
新製品は、価格、カテゴリ、公開などのすべてのデータとともに、管理エリアにうまく表示されます。
しかし、何らかの理由で、新しい製品を開いて編集し、更新をクリックするまで、Web サイトのショップ ページに表示されません。
誰か?