Le site loue des chambres à l'heure.
J'utilise le plugin "WooCommerce Bookings And Appointments" sur mon site Web. L'URL du plugin est https://www.pluginhive.com/product/woocommerce-booking-and-appointments/
Le plugin prend en charge les règles de co?t et je peux contr?ler le prix à tout moment. Mais je ne trouve pas de solution pour mon scénario spécifique.
Si le client choisit une heure entre 22h et 10h.
Et le délai minimum de commandeest supérieur à 6 heures.
Ensuite le prix sera de 6 heures .
La période de réservation est fixée dans les paramètres généraux, 30 minutes par séance.
Paramètres des frais de réservation?: 3 heures prix minimum est de 300 $ (nous utilisons les règles des blocs 1 à 6).
Tarif de base de la chambre?: 300$ (les clients peuvent commander moins de 3 heures, mais le prix est d'un minimum de 3 heures).
Co?t du bloc?:?50?$ (en commen?ant par le bloc numéro 7).
Exemple de scène?:
Si un client commande 4 heures de 23h à 3h du matin (blocs total : 8), le prix sera le prix régulier : 400$ (co?t de base : 300$ + 100$ [2 blocs, 50$ chacun])
Si un client commande 5 heures de 23h à 4h du matin (blocs total : 10), le prix sera le prix régulier : 500$
Si le client commande 6 heures de 23h à 5h (blocs total : 12), le prix sera le prix régulier : 600$
Si un client commande 7 heures de 23h à 6h du matin (blocs total : 14), le prix sera de 600$ au lieu de 700$
Si un client commande 8 heures de 23h à 7h (blocs total : 16), le prix sera de 600$ au lieu de 800$
Si un client commande 6 heures de 21h à 3h du matin (blocs totaux : 12), le prix sera de 600$
Si un client commande 21h à 4h du matin pendant 7 heures (blocs total : 14), le prix sera de 600$ au lieu de 700$
Si un client commande 21h à 5h du matin pour 8 heures (blocs total : 16), le prix sera de 600$ au lieu de 800$
Si un client commande dans les 14 heures entre 21h et 11h (blocs totaux : 28), le prix sera de 800$ au lieu de 1400$
J'ai essayé de suivre cet article pour fixer les prix en fonction de la durée des réservations WooCommerce et d'ajuster mon problème, mais sans succès.
J'ai créé l'extrait de code mais je ne vois aucun changement. Vérifiez ce lien vers l'aper?u en direct
<?php // Calculates price based on selected booking start time and minimum order hours add_action( 'woocommerce_before_calculate_totals', 'cwpai_booking_price_calculation', 10, 1 ); function cwpai_booking_price_calculation( $cart ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { return; } foreach ( $cart->get_cart() as $cart_item ) { $product_id = $cart_item['product_id']; // Get start time and minimum order hours $start_time = strtotime($_POST['wc_bookings_field_start_date'][0] . ' ' . $_POST['wc_bookings_field_start_time'][0]); $minimum_hours = get_post_meta( $product_id, '_minimum_duration', true ); // Check if start time and minimum order hours meet condition if ( date('H:i', $start_time) >= '22:00' && date('H:i', $start_time) <= '10:00' && $minimum_hours >= 6 ) { // Calculate maximum cost for 6 hours $max_cost = $cart_item['data']->get_price() * 6; // Get current cost based on duration $duration = WC_Bookings_Cart::calculate_booking_duration( $cart_item['booking'], true, true ); $current_cost = $duration['cost']; // Update cost to maximum cost for 6 hours if ( $current_cost > $max_cost ) { $cart_item['data']->set_price( $max_cost ); } } } } // Update post meta when product is saved add_action( 'woocommerce_process_product_meta', 'cwpai_update_booking_meta' ); function cwpai_update_booking_meta( $post_id ) { // Only run for bookable products if ( get_post_meta( $post_id, '_wc_booking_type', true ) !== 'booking' ) { return; } // Get minimum order hours $minimum_hours = isset( $_POST['_minimum_duration'] ) ? absint( $_POST['_minimum_duration'] ) : 0; // Update post meta with new booking cost if ( $minimum_hours >= 6 ) { $max_cost = get_post_meta( $post_id, '_price', true ) * 6; update_post_meta( $post_id, '_new_booking_cost', $max_cost ); } else { delete_post_meta( $post_id, '_new_booking_cost' ); } } // Modify product costs to new booking cost add_filter( 'woocommerce_product_get_price', 'cwpai_modify_product_costs', 10, 2 ); add_filter( 'woocommerce_product_get_regular_price', 'cwpai_modify_product_costs', 10, 2 ); function cwpai_modify_product_costs( $price, $product ) { $new_booking_cost = get_post_meta( $product->get_id(), '_new_booking_cost', true ); if ( $new_booking_cost ) { $price = $new_booking_cost; } return $price; }