0.00  View Cart

To sync the availabilities of all your products’ translations, add this code to your theme’s functions.php:

add_action( 'ebac_order_processed', 'ebac_polylang_compatibility', 10, 3 );

function ebac_polylang_compatibility( $quantity, $keep_stock_id, $booked ) {

    if ( function_exists( 'pll_get_post_translations' ) ) {

        $pll_translations = pll_get_post_translations( $keep_stock_id );

        if ( $pll_translations ) {

            foreach ( $pll_translations as $language => $ID ) {
                if ( $keep_stock_id != $ID ) { 

                    add_post_meta( $ID, '_booking_days', $booked, true ) || update_post_meta( $ID, '_booking_days', $booked );
		            
                }
            }

        }

    }

}

add_filter( 'ebac_booked_products', 'ebac_booked_products_polylang', 10, 1 );

function ebac_booked_products_polylang( $products ) {

    if ( function_exists( 'pll_get_post_translations' ) ) {

        if ( ! empty( $products ) ) foreach ( $products as $product ) {

            $id = $product['product_id'];
            $pll_translations = pll_get_post_translations( $id );

            if ( $pll_translations ) {

                foreach ( $pll_translations as $language => $ID ) {

                    if ( $id != $ID ) {

                        $products[] = array(
                            'product_id' => $ID,
                            'start'      => $product['start'],
                            'end'        => $product['end'],
                            'qty'        => $product['qty']
                        );

                    }

                }

            }

        }

    }

    return $products;
}

add_filter( 'ebac_delete_stock_ids', 'ebac_polylang_delete_stock_ids', 10, 2 );

function ebac_polylang_delete_stock_ids( $ids, $id ) {

    if ( function_exists( 'pll_get_post_translations' ) ) {

        $pll_translations = pll_get_post_translations( $id );

        if ( $pll_translations ) {

            foreach ( $pll_translations as $language => $ID ) {
                if ( $id != $ID ) {
                    $ids[] = $ID;
                }
            }

        }

    }

    return $ids;

}