woocommerce add custom post type to cart

前端 未结 3 1899
猫巷女王i
猫巷女王i 2021-01-03 17:44

I\'m using woocommerce and i created a custom post type that has to be treated as a product and user may add to cart. I followed this tutorial http://reigelgallarde.me/prog

3条回答
  •  独厮守ぢ
    2021-01-03 18:02

    If you already have a meta key which is not _price, you can add a filter to woocommerce_get_price shown below.

      add_filter('woocommerce_get_price','reigel_woocommerce_get_price',20,2);
        function reigel_woocommerce_get_price($price,$post){
            if ($post->post->post_type === 'post') // change this to your post type
                $price = get_post_meta($post->id, "price", true); // your price meta key is price
            return $price;
        }
    

提交回复
热议问题