sql >> Database teknologi >  >> RDS >> Mysql

Få prisdata for et produkt, der kan reserveres, med datointervaller i WooCommerce

Til WooCommerce Bookings har du alt det nødvendige i WC_Product_Booking objekt:

// Get an instance of the WC_Product object (Here a WC_Product_Booking object)
$product = wc_get_product( $product_id );

// Get the base price
$base_price = $product->get_price();

// Get all related protected data in an array
$product_data = $product->get_data();

// Get the additional pricing data for this bookable product (array)
$product_pricing = $product_data['pricing'];

// iterating through each pricing row
foreach($product_pricing as $key => $princing ){
    $pricing_type           = $princing['type'];
    $pricing_base_cost      = $princing['base_cost']; // <= this is the price you are looking for
    $pricing_base_modifier  = $princing['base_modifier'];
    $pricing_cost           = $princing['cost']; 
    $pricing_modifier       = $princing['modifier'];
    $pricing_from           = $princing['from'];
    $pricing_to             = $princing['to'];
}

// Raw pricing data output (for tests)
echo '<pre>'; print_r($product_pricing); echo '</pre>';
';

Nu i databasen kan du finde disse data i wp_post_meta tabel under _wc_booking_pricing meta_key … Så fra produkt-id'et kan du også få adgang til det med:

$pricing_data = get_post_meta( $product_id, '_wc_booking_pricing', false);

// Raw pricing data output (for tests)
echo '<pre>'; print_r($product_pricing); echo '</pre>';
';

  1. MySQL-visningsydelse

  2. Ydelsesmyter:Truncate kan ikke rulles tilbage

  3. Brug af Spotlight Cloud til at løse SQL Server-blokering

  4. Indsamlingsmetode:UDVID Procedure i Oracle-databasen