下面的代码应该更改通过特定支付方法(untested)传递的订单的持有股票(60 minutes by default)的时间.
请参见How to get the ID of a payment method in WooCommerce?.
下面,在函数内部,您将定义所需的支付方式(S)ID(S)(for your cryptocurrency payment option(s))和所需的持有股票的时间(分钟):
add_action( 'woocommerce_checkout_order_created', 'wc_reserve_stock_for_crypto', 5 );
function wc_reserve_stock_for_crypto( $order ) {
// HERE below define the desired payment ID(s)
$targeted_payment_ids = array('coinbase', 'coinpayments');
// HERE below define the time in minutes to hold stock
$hold_stock_minutes = 150;
if ( in_array( $order->get_payment_method(), $targeted_payment_ids ) ) {
// Remove the default functionality to hold stock for 60 minutes
remove_action( 'woocommerce_checkout_order_created', 'wc_reserve_stock_for_order' );
if ( ! apply_filters( 'woocommerce_hold_stock_for_checkout', wc_string_to_bool( get_option( 'woocommerce_manage_stock', 'yes' ) ) ) ) {
return;
}
$order = $order instanceof WC_Order ? $order : wc_get_order( $order );
if ( $order ) {
// Add back the functionality with a custom delay to hold the stock
( new \Automattic\WooCommerce\Checkout\Helpers\ReserveStock() )->reserve_stock_for_order( $order, $hold_stock_minutes );
}
}
}
代码位于您的子主题的unctions.php文件中(或在插件中).应该能行得通.