我有nex代码,但它仅适用于简单的产品,并且不考虑产品的数量或变体。
add_action( 'woocommerce_after_add_to_cart_quantity', 'by_now' );
function by_now() {
$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 '<div class="test"><a href="'.$checkout_url.'?add-to-cart='.$current_product_id.'"
type="submit"class="single_add_to_cart_button button alt">Pagar ahora</a></div>';
}