搜索一下,你就知道

< 返回
当前位置:
打印

添加Buy now 按钮-针对simple产品

目录
/*加入主题functions.php文件, Create Buy Now Button dynamically after Add To Cart button */
function add_content_after_addtocart() {
    
// get the current post/product ID
$current_product_id = get_the_ID();
    
// get the product based on the ID
$product = wc_get_product( $current_product_id );
    
// get the "Checkout Page" URL
$checkout_url = WC()->cart->get_checkout_url();
    
// run only on simple products
if( $product->is_type( 'simple' ) ){
echo '<a href="'.$checkout_url.'?add-to-cart='.$current_product_id.'" class="buy-now button">Buy Now</a>';
// echo '<a href="'.$checkout_url.'" class="buy-now button">Buy Now</a>';
}
}
add_action( 'woocommerce_after_add_to_cart_button', 'add_content_after_addtocart' );

登录

还没有账户?

开始输入你要找的文章。
微信

微信号:hackenwu

商店
0 项目 购物车