php 转换订单从处理到完成WooCommerce(WordPress)

tv6aics1  于 2023-02-15  发布在  PHP
关注(0)|答案(1)|浏览(96)

我第一次使用人工智能
但是你告诉我的密码不起作用
将静脉从治疗自动转换为30秒后完成
仅限虚拟产品
具体支付方式有两种
但它不起作用

// Add a 30 second delay for virtual products
add_filter( 'woocommerce_payment_complete_order_status', 'wc_delay_virtual_order', 10, 2 );
function wc_delay_virtual_order( $order_status, $order ) {
    if ( $order->has_downloadable_item() && ! $order->has_status( 'completed' ) ) {
        return 'on-hold'; // change to any other status you wish to use.
    }

    return $order_status;
}
add_action( 'woocommerce_thankyou', 'wc_delay_virtual', 30 );
function wc_delay_virtual( $orderid ) { 

    // Get the order object and check for downloadable items. 
    $order = new WCOrder($orderid); 

    if ( $order->hasDownloadableItem() ) { 

        // Set a 30 second delay for virtual products. 
        sleep(30); 

        // Update the order status to complete. 
        $order->updateStatus('completed');  

    }  
}  
// Add a custom payment gateway for MobileWallet and Reference Code payments. 
add-filter('woocommerce-payment-gateways','wc-add-mobilewallet-referencecode'); 
function wc-add-mobilewallet-referencecode($methods){ 

 $methods[] = 'WCMobileWallet'; // MobileWallet payment gateway class name.  

 $methods[] = 'WCReferenceCode'; // Reference Code payment gateway class name.  

 return $methods;  
}

我试着把这个代码添加到插件和function.php里面我正在等待你的回复来解决我的问题,谢谢

hsvhsicv

hsvhsicv1#

下面发布的代码部分有一个问题。您不能在函数名之间使用-,如wc-add-mobilewallet-referencecode,而应该使用wc_add_mobilewallet_referencecode和下划线“_”
正确的代码应该如下所示:

add_filter('woocommerce-payment-gateways','wc_add_mobilewallet_referencecode'); 
function wc_add_mobilewallet_referencecode($methods){ 

 $methods[] = 'WCMobileWallet'; // MobileWallet payment gateway class name.  

 $methods[] = 'WCReferenceCode'; // Reference Code payment gateway class name.  

 return $methods;  
}

由于您只需要更改订单状态以完成可下载的产品,只需下面的代码:

add_filter( 'woocommerce_payment_complete_order_status', 'wc_delay_virtual_order', 10, 2 );
function wc_delay_virtual_order( $order_status, $order ) {
    if ( $order->has_downloadable_item() && ! $order->has_status( 'completed' ) ) {
        sleep(30);
        return 'completed'; //Here should be complete.
    }

  return $order_status;
}

相关问题