我需要判断是否正在使用此代码购买特定产品,但它不起作用.
function validate($data,$errors) {
if ( ( is_product() && get_the_ID() == 1566 ) || is_single('1566') ) {
return;
$p = wc_get_product('1566');
$message = sprintf( __( '%s can only be purchased by some customers.</div>', 'text-domain' ), $p->get_name() );
wc_add_notice( $message, 'error' );
}
}
add_action('woocommerce_after_checkout_validation', 'validate',10,2);