从NavigationView层次结构SwiftUI的子视图中调用的NotificationCenter.default.publisher

时间:2020-04-22 19:11:15

标签: swift xcode swiftui combine notificationcenter

代码

function handmade_woocommerce_order( $order_id ) {
    if( ! $order_id ) return;

    // Get order
    $order = wc_get_order( $order_id );

    // get order items = each product in the order
    $items = $order->get_items();

    // Set variable
    $found = false;

    foreach ( $items as $item ) {
        // Get product id
        $product = wc_get_product( $item['product_id'] );

        // Is virtual
        $is_virtual = $product->is_virtual();

        // Is_downloadable
        $is_downloadable = $product->is_downloadable();
        
        // Backorders allowed
        $backorders_allowed = $product->backorders_allowed();

        if( $is_virtual && $is_downloadable && $backorders_allowed ) {
            $found = true;
            // true, break loop
            break;
        }
    }

    // true
    if( $found ) {
        $order->update_status( 'processing' );
    }
}
add_action('woocommerce_thankyou', 'handmade_woocommerce_order', 10, 1 );

当前行为:

上面的代码将针对我的层次结构中的每个视图执行。

问题:

如何仅针对特定视图接收.onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardWillShowNotification))

0 个答案:

没有答案