/** * Theme functions and definitions. * * For additional information on potential customization options, * read the developers' documentation: * * https://developers.elementor.com/docs/hello-elementor-theme/ * * @package HelloElementorChild */ if (! defined('ABSPATH')) { exit; // Exit if accessed directly. } define('HELLO_ELEMENTOR_CHILD_VERSION', '2.0.0'); /** * Load child theme scripts & styles. * * @return void */ function hello_elementor_child_scripts_styles() { wp_enqueue_style( 'hello-elementor-child-style', get_stylesheet_directory_uri() . '/style.css', [ 'hello-elementor-theme-style', ], HELLO_ELEMENTOR_CHILD_VERSION ); } add_action('wp_enqueue_scripts', 'hello_elementor_child_scripts_styles', 20); // New actions to split up cart totals and cross sell on cart page add_action('hproc_woocommerce_cart_totals', 'woocommerce_cart_totals', 10); add_action('hproc_woocommerce_cart_cross_sell', 'woocommerce_cross_sell_display'); add_action('acf/init', 'set_acf_settings'); function set_acf_settings() { acf_update_setting('enable_shortcode', true); } function custom_short_description_shortcode() { global $post; $short_description = get_the_excerpt($post->ID); $max_length = 40; // Maximalt antal tecken if (strlen($short_description) > $max_length) { $short_description = substr($short_description, 0, $max_length) . '...'; } return '
' . $short_description . '
'; } add_shortcode('short_description', 'custom_short_description_shortcode'); // // Helpers // function hproc_dump($value) { echo "
";
	print_r($value);
	echo "
"; } /* Lägger till is_reseller och is_company i get order rest api svaret */ add_filter('woocommerce_rest_prepare_shop_order_object', 'hproc_wc_rest_api_extend_order_lineitems_data', 10, 3); function hproc_wc_rest_api_extend_order_lineitems_data($response, $object, $request) { if (empty($response->data)) { return $response; } /* Plockar ut order data från svaret */ $order_data = $response->get_data(); /* Hämta user objektet via ID. customer_id finns på order objektet */ $user = get_user_by("id", $order_data["customer_id"]); /* Är user objektet tomt skickar vi false */ if (empty($user)) { $order_data["is_reseller"] = false; $order_data["is_company"] = false; $order_data["user_email"] = ""; } else { /* Plocka ut alla roller från user objektet */ $roles = $user->roles; /* Om rollerna är tom skickar vi false */ if (empty($roles) || count($roles) <= 0) { $order_data["is_reseller"] = false; $order_data["is_company"] = false; } else { $isReseller = false; $isCompany = false; /* $user->roles är en array även om man bara kan sätta 1 roll. Gör en foreach om detta ändras framöver. */ foreach ($roles as $role) { /* Om rollen börjar med b2b hanterar vi denna som ÅF roll och sätter $isReseller till true */ if (substr_compare($role, "b2b", 0, 3, true) === 0) { $isReseller = true; $isCompany = true; } if ($role == "company") { $isCompany = true; } } $order_data["is_reseller"] = $isReseller; $order_data["is_company"] = $isCompany; } $order_data["user_email"] = $user->user_email; } /* Sätter momsklass i API svaret */ $taxLines = $order_data["tax_lines"]; if (!empty($taxLines)) { $taxLinesIsUpdated = false; foreach ($taxLines as &$taxLine) { $taxLabel = $taxLine["label"]; if (empty($taxLabel)) { continue; } $taxLabelArray = explode(",", $taxLabel); if (empty($taxLabelArray) || count($taxLabelArray) != 2) { continue; } $taxCode = $taxLabelArray[1]; if (empty($taxCode) && $taxCode != 0) { continue; } $taxLine["pyramid_tax_code"] = $taxCode; if (!$taxLinesIsUpdated) { $taxLinesIsUpdated = true; } } if ($taxLinesIsUpdated) { $order_data["tax_lines"] = $taxLines; } } $lineItems = $order_data["line_items"]; if (!empty($lineItems)) { $lineItemsIsUpdated = false; foreach ($lineItems as &$lineItem) { $lineTaxItems = $lineItem["taxes"]; if (!empty($lineTaxItems)) { foreach ($lineTaxItems as &$lineTaxItem) { $lineTaxItem["pyramid_tax_code"] = searchPyramidTaxCodeById($lineTaxItem["id"], $order_data["tax_lines"]); if (!$lineItemsIsUpdated) { $lineItemsIsUpdated = true; } } } else { /** * Om vi inte har några taxlines är produkten momsfri. Vi måste endå skicka med pyramid_tax_code. * Utifrån fraktsätt (instance id) kan vi sätta rätt momskod. * */ $shippingLines = $order_data["shipping_lines"]; if (!empty($shippingLines)) { /** * Finns ingen logik för fler leveranssätt. Tar första i array'en. * */ $shippingLine = $shippingLines[0]; if (!empty($shippingLine)) { $shippingInstanceId = $shippingLine["instance_id"]; /** * Svenska instance_id */ $swedishShippingIds = ["20", "27", "28", "4", "10"]; /** * EU instance id */ $euShippingIds = ["29", "30", "21"]; /** * EXPORT instance id */ $exportShippingIds = ["31", "32", "22"]; $pyramidTaxCode = null; if (in_array($shippingInstanceId, $swedishShippingIds)) { $pyramidTaxCode = "4"; } else if (in_array($shippingInstanceId, $euShippingIds)) { $pyramidTaxCode = "9"; } else if (in_array($shippingInstanceId, $exportShippingIds)) { $pyramidTaxCode = "0"; } $lineTaxItems = [ [ "pyramid_tax_code" => $pyramidTaxCode ] ]; if (!$lineItemsIsUpdated) { $lineItemsIsUpdated = true; } } } } $lineItem["taxes"] = $lineTaxItems; } if ($lineItemsIsUpdated) { $order_data["line_items"] = $lineItems; } } $response->data = $order_data; return $response; } function searchPyramidTaxCodeById($id, $array) { foreach ($array as $key => $val) { if ($val['rate_id'] === $id) { return $val['pyramid_tax_code']; } } return null; } /** * Ändra valuta symbol */ add_filter('woocommerce_currency_symbol', 'hproc_currency_symbol', 10, 2); function hproc_currency_symbol($currency_symbol, $currency) { switch ($currency) { case "SEK": $currency_symbol = "SEK"; break; case "EUR": $currency_symbol = "EUR"; break; case "NOK": $currency_symbol = "NOK"; break; case "DKK": $currency_symbol = "DKK"; break; } return $currency_symbol; } /** * Visa SKU i cart och checkout */ add_filter('woocommerce_cart_item_name', 'hproc_sku_cart_page', 99, 3); function hproc_sku_cart_page($item_name, $cart_item, $cart_item_key) { // The WC_Product object $product = $cart_item['data']; // Get the SKU $sku = $product->get_sku(); // When sku doesn't exist if (empty($sku)) return $item_name; // Add the sku $item_name .= '
' . __("SKU: ", "woocommerce") . $sku . ''; return $item_name; } /** * Skicka ett mail om ÅF ändrar billing eller shipping informationen. * https://stackoverflow.com/questions/31270846/send-notification-email-when-customer-changes-address-woocommerce */ add_action('woocommerce_customer_save_address', 'hproc_email_customer_address_change'); function hproc_email_customer_address_change() { $body = ''; $to = 'jessica.brixeby@gysinge.com'; //address that will receive this email //$to = 'patrick.andersson@100procent.com'; //address that will receive this email //$to = 'mattias@100procent.com'; //address that will receive this email $subject = 'En av återförsäljarna har uppdaterat sin adress.'; $sendNotification = false; $curr_user = wp_get_current_user(); if ($curr_user) { /** * Check if the user is retailer */ foreach ($curr_user->roles as $role) { if (substr_compare($role, "b2b", 0, 3, true) === 0 /*|| $role === "administrator"*/) { $sendNotification = true; break; } } if ($sendNotification) { $user_id = $curr_user->ID; $curr_username = $curr_user->data->user_login; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= '
Konto
Användarnamn: ' . $curr_username . '
Orgaisationsnummer: ' . get_field('field_67b5b586a2d06', 'user_' . $user_id) . '
 
Faktureringsadress
Förnamn: ' . get_user_meta($user_id, 'billing_first_name', true) . '
Efternamn: ' . get_user_meta($user_id, 'billing_last_name', true) . '
Företag: ' . get_user_meta($user_id, 'billing_company', true) . '
Adress 1: ' . get_user_meta($user_id, 'billing_address_1', true) . '
Adress 2: ' . get_user_meta($user_id, 'billing_address_2', true) . '
Stad: ' . get_user_meta($user_id, 'billing_city', true) . '
Postnummer: ' . get_user_meta($user_id, 'billing_postcode', true) . '
Land: ' . get_user_meta($user_id, 'billing_country', true) . '
Telefon: ' . get_user_meta($user_id, 'billing_phone', true) . '
Email: ' . get_user_meta($user_id, 'billing_email', true) . '
 
Leveransadress
Förnamn: ' . get_user_meta($user_id, 'shipping_first_name', true) . '
Efternamn: ' . get_user_meta($user_id, 'shipping_last_name', true) . '
Företag: ' . get_user_meta($user_id, 'shipping_company', true) . '
Adress 1: ' . get_user_meta($user_id, 'shipping_address_1', true) . '
Adress 2: ' . get_user_meta($user_id, 'shipping_address_2', true) . '
Stad: ' . get_user_meta($user_id, 'shipping_city', true) . '
Postnummer: ' . get_user_meta($user_id, 'shipping_postcode', true) . '
Land: ' . get_user_meta($user_id, 'shipping_country', true) . '
'; //set content type as HTML $headers = array('Content-Type: text/html; charset=UTF-8;'); //send email if (wp_mail($to, $subject, $body, $headers)) { //echo 'email sent'; } else { //echo 'email NOT sent'; } //exit(); } } } // Enables search on headline of articles add_filter('dgwt/wcas/indexer/post_types', function ($post_types) { $post_types[] = [ 'post_type' => 'article', 'labels' => [ 'name' => 'Textartiklar', ], ]; return $post_types; }); //Enables search within the discription add_filter('dgwt/wcas/indexer/post_source_query/article/description', '__return_true'); //Showing CPT image in search result add_filter('dgwt/wcas/search_results/article/show_image', '__return_true'); // Display custom post types on the search result page add_action('woocommerce_no_products_found', function () { if (! \DgoraWcas\Helpers::isProductSearchPage()) { return; } echo do_shortcode('[fibosearch_posts_results post_type="article" layout=grid show_image]'); }); add_action('woocommerce_before_shop_loop', function () { if (! \DgoraWcas\Helpers::isProductSearchPage()) { return; } echo do_shortcode('[fibosearch_posts_results post_type="article" layout=grid show_image]'); }); ?> {"version":"1.0","provider_name":"Gysinge","provider_url":"https:\/\/www.gysinge.com\/en\/","author_name":"Emelie Wilhelmsson","author_url":"https:\/\/www.gysinge.com\/en\/author\/emelie-wilhelmsson\/","title":"Window renovation day","type":"rich","width":600,"height":338,"html":"
Window renovation day<\/a><\/blockquote>