Custom Function
-
I’m trying to add a custom function to the functions.php page yet I seem to be getting an internal server error. Any ideas?
The offending code string is this:
$query1 = "SELECT order_item_id, order_item_name FROM
wp_woocommerce_order_itemsWHERE order_item_type = 'line_item' AND order_id = $order_id ";
When I attempt to execute the sql it shows an internal server error message on the store checkout page.
Here is a portion of what does work…
The queries are in the middle of this and have been taken out.add_action("woocommerce_checkout_order_processed", "hubspot_tie_in"); function hubspot_tie_in($order_id) { global $woocommerce; $checkout = $woocommerce->checkout(); $order = new WC_Order( $order_id ); do_action( 'woocommerce_email_before_order_table', $order, true ); $order_number_formatted = $checkout->get_value( 'order_number' ); $billing_country = $checkout->get_value( 'billing_country' ); $billing_first_name = $checkout->get_value( 'billing_first_name' ); $billing_last_name = $checkout->get_value( 'billing_last_name' ); $billing_address_1 = $checkout->get_value( 'billing_address_1' ); $billing_address_2 = $checkout->get_value( 'billing_address_2' ); $billing_city = $checkout->get_value( 'billing_city' ); $billing_state = $checkout->get_value( 'billing_state' ); $billing_postcode = $checkout->get_value( 'billing_postcode' ); $billing_email = $checkout->get_value( 'billing_email' ); $billing_phone = $checkout->get_value( 'billing_phone' ); $order_shipping = $checkout->get_value( 'order_shipping' ); $order_discount = $checkout->get_value( 'order_discount' ); $total_tax = $checkout->get_value( 'order_tax' ); $order_total = $checkout->get_value( 'order_total' ); $customer_user_agent = $checkout->get_value( 'customer_user_agent' ); $store_used = 'MyWebStore.com'; $base_currency = 'USD'; $lifecyclestage = 'customer'; $hs_context = array( 'eyemagine_order_item_product_url_1' => '$eyemagine_order_item_product_url_1', 'eyemagine_order_item_product_url_2' => '$eyemagine_order_item_product_url_2', 'eyemagine_order_item_product_url_3' => '$eyemagine_order_item_product_url_3', 'store_used' => '$store_used', 'country' => '$billing_country', 'firstname' => '$billing_first_name', 'lastname' => '$billing_last_name', 'address' => '$billing_address_1', 'address+address' => '$billing_address_2', 'city' => '$billing_city', 'state' => '$billing_state', 'zip' => '$billing_postcode', 'email' => '$billing_email', 'phone' => '$billing_phone', 'lifecyclestage' => '$lifecyclestage', 'eyemagine_order_increment_id' => '$order_number', 'eyemagine_order_created_at' => '$completed_date', 'eyemagine_order_item_product_name_1' => '$eyemagine_order_item_product_name_1', 'eyemagine_order_item_product_name_2' => '$eyemagine_order_item_product_name_2', 'eyemagine_order_item_product_name_3' => '$eyemagine_order_item_product_name_3', 'eyemagine_order_base_currency' => '$base_currency', 'eyemagine_order_subtotal' => '$order_subtotal', 'eyemagine_order_discount' => '$order_discount', 'eyemagine_order_tax' => '$total_tax', 'eyemagine_order_shipping' => '$order_shipping', 'eyemagine_order_grand_total' => '$order_total' ); $hs_context_json = json_encode($hs_context); $str_post = "firstname=" . urlencode($billing_first_name) . "&lastname=" . urlencode($billing_last_name) . "&lifecyclestage=" . urlencode($lifecyclestage) . "&eyemagine_order_item_product_url_1=" . urlencode($eyemagine_order_item_product_url_1) . "&eyemagine_order_item_product_url_2=" . urlencode($eyemagine_order_item_product_url_2) . "&eyemagine_order_item_product_url_3=" . urlencode($eyemagine_order_item_product_url_3) . "&store_used=" . urlencode($store_used) . "&country=" . urlencode($billing_country) . "&address=" . urlencode($billing_address_1) . "&address+address=" . urlencode($billing_address_2) . "&city=" . urlencode($billing_city) . "&state=" . urlencode($billing_state) . "&zip=" . urlencode($billing_postcode) . "&email=" . urlencode($billing_email) . "&phone=" . urlencode($billing_phone) . "&eyemagine_order_increment_id=" . urlencode($order_number) . "&eyemagine_order_created_at=" . urlencode($completed_date) . "&eyemagine_order_item_product_name_1=" . urlencode($eyemagine_order_item_product_name_1) . "&eyemagine_order_item_product_name_2=" . urlencode($eyemagine_order_item_product_name_2) . "&eyemagine_order_item_product_name_3=" . urlencode($eyemagine_order_item_product_name_3) . "&eyemagine_order_base_currency=" . urlencode($base_currency) . "&eyemagine_order_subtotal=" . urlencode($order_subtotal) . "&eyemagine_order_discount=" . urlencode($order_discount) . "&eyemagine_order_tax=" . urlencode($total_tax) . "&eyemagine_order_shipping=" . urlencode($order_shipping) . "&eyemagine_order_grand_total=" . urlencode($order_total) . "&hs_context=" . urlencode($hs_context_json); //I replaced the values in this URL for Privacy $endpoint = 'https://forms.hubspot.com/uploads/form/v2/MyHubspotID/MyHubspotFormGUID'; $ch = @curl_init(); @curl_setopt($ch, CURLOPT_POST, true); @curl_setopt($ch, CURLOPT_POSTFIELDS, $str_post); @curl_setopt($ch, CURLOPT_URL, $endpoint); @curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $hs_response = @curl_exec($ch); //Log the response from HubSpot as needed. @curl_close($ch); }
I’d be grateful for any help.
Thanks!
Steve
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Custom Function’ is closed to new replies.