In WooCommerce verwende ich das WC -Kalkulator -Plugin für ein einfaches Produkt (ID 4692). Das Problem ist, dass dieses einfache Produkt nur statische Gewichts- und Abmessungswerte aufweist, die in jede Hinzufügung von Wagenelementen gezogen werden. Das macht ein 12 -"x12" -Schild -Panel mit einem Gewicht von 2 Pfund, der das gleiche als Panel 120 "x 48" bei 80 lbs kostet. Ich habe Felder im WC -Kalkulator -Plugin eingerichtet, um das berechnete Gewicht und die berechneten Abmessungen zu definieren. in den Wagen. Jede Instanz des CART -Elements sollte für die eingegebenen Werte eindeutig sein. Br />add_action( 'woocommerce_before_calculate_totals', 'update_custom_price', 10, 1 );
function update_custom_price( $cart_object ) {
foreach ( $cart_object->get_cart() as $cart_item ) {
// Get the WC_Product object
$product = $cart_item['data'];
$product_id = $product->get_id();
// Check if the product ID matches the specific product
if ( $product_id == 4692 ) {
// Get the custom field value
$custom_field_value = get_post_meta( 4692, 'wck_weight', true );
$custom_field_value1 = get_post_meta( 4692, 'wck_length', true );
$custom_field_value2 = get_post_meta( 4692, 'wck_width', true );
$custom_field_value3 = get_post_meta( 4692, 'wck_height', true );
// Update the product weight and dimensions
$product->set_weight( $custom_field_value );
$product->set_length( $custom_field_value1 );
$product->set_width( $custom_field_value2 );
$product->set_height( $custom_field_value3 );
}
}
}
< /code>
Ich weiß nicht, ob die "get_post_meta" an der richtigen Stelle sucht, um die WCK -Felder zu finden. Die Felder sind korrekt benannt und die Produkt -ID ist für meine Absichten korrekt.
Verwenden Sie WC Kalkulator -Produktfeldwerte, um die Produkteigenschaften von WooCommerce Cart Item -Produkte zu aktual ⇐ Php
-
- Similar Topics
- Replies
- Views
- Last post