Kontaktformular 7 vor dem Senden der E-Mail

Ich versuche Feldwerte aus dem Kontaktformular 7 in WordPress abzurufen und dann einige Berechnungen durchzuführen. Danach überprüfe ich, ob das Produkt bereits im Warenkorb ist und wenn nicht, wird es per Code hinzugefügt. Das, was ich erreichen möchte, aber ich kann nicht herausfinden, was in meinem Code falsch ist. Brauche Hilfe bitte. Das Kontaktformular wird geladen und das Produkt wird nicht in den Warenkorb gelegt.

function action_wpcf7_before_send_mail( $contact_form ) { global $tour_id; global $final_price; global $woocommerce; $submission = WPCF7_Submission::get_instance(); if ( $submission ) { $posted_data = $submission->get_posted_data(); } $cm_mail = $posted_data['cm-email']; $tour_id = $posted_data['tour-id']; $tour_price = $posted_data['tour-price']; $tour_discount_price = $posted_data['tour-discount-price']; if( empty( $tour_discount_price ) ) { $tour_final_price = $tour_price; } else { $tour_final_price = $tour_discount_price; } $tour_date = $posted_data['tour-date']; $adult_no = $posted_data['no-adult']; $child_no = $posted_data['no-child']; $total_pax = array( $adult_no, $child_no ); if( sum( $total_pax ) >= 1 ){ $final_price = $tour_final_price * 1; } if( sum( $total_pax ) >= 3 ){ $final_price = $tour_final_price * 0.8; } else if( sum( $total_pax ) >= 7 ){ $final_price = $tour_final_price * 0.6; } else if( sum( $total_pax ) >= 16 ){ $final_price = $tour_final_price * 0.4; } else { $final_price = 0; } if( 0 cart->add_to_cart( $tour_id ); } } remove_all_filters( 'wpcf7_before_send_mail' ); add_action( 'wpcf7_before_send_mail', 'action_wpcf7_before_send_mail' ); /*==============================================================================================*/ /*==============================================================================================*/ function matched_cart_items( $product_id ) { if( !WC()->cart->is_empty() ) : // Initialise the count $count = 0; foreach( WC()->cart->get_cart() as $cart_item ) : $items_id = $cart_item['product_id']; // For an array of product IDS if( is_array( $product_id ) && in_array( $items_id, $product_id ) ) { $count++; // incrementing the counted items } // for a unique product ID (integer or string value) if( $product_id == $items_id ) { $count++; // incrementing the counted items } endforeach; // returning counted items return $count; endif; } 

Solutions Collecting From Web of "Kontaktformular 7 vor dem Senden der E-Mail"