我已经在帖子中添加了“添加到购物车”按钮(对于带有type = post的帖子),具有相同的POST结束点,例如“添加到购物车”功能(使用type = product),但无法正常工作,就像那样:
<?php
add_filter('woocommerce_get_price','reigel_woocommerce_get_price',20,2);
function reigel_woocommerce_get_price($price,$post){
if ($post->post->post_type === 'post')
$price = get_post_meta($post->id, "price", true);
return $price;
}
add_filter('the_content','rei_add_to_cart_button', 20,1);
function rei_add_to_cart_button($content){
global $post;
if ($post->post_type !== 'post') {return $content; }
ob_start();
?>
<form action="" method="post">
<input name="add-to-cart" type="hidden" value="<?php echo $post->ID ?>" />
<input name="quantity" type="number" value="1" min="1" />
<input name="submit" type="submit" value="Add to cart" />
</form>
<?php
return $content . ob_get_clean();
}
?>
参考:http://reigelgallarde.me/programming/how-to-add-custom-post-type-to-woocommerce/
感谢您的支持!