/** * 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 '
"; 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 .= '
| 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) . ' |
Detta enstaka uppm\u00e5lat f\u00e4rgprov ger dig m\u00f6jlighet att se och k\u00e4nna p\u00e5 v\u00e5ra tidsenliga linoljef\u00e4rger innan du best\u00e4mmer dig f\u00f6r ditt n\u00e4sta m\u00e5larprojekt. V\u00e4lj bland v\u00e5rt noggrant utvalda sortiment av standardkul\u00f6rer och hitta den perfekta nyansen som passar just ditt hem. Med linoljef\u00e4rg f\u00e5r du inte bara en vacker finish, utan \u00e4ven en produkt som andas och skyddar dina ytor.<\/p>\n
V\u00e4lj antal kul\u00f6rprov du vill best\u00e4lla och l\u00e4gg i varukorgen.<\/p>\n
N\u00e4r du sen kommer till kassan.<\/strong><\/p>\n Skriv i kommentarsf\u00e4ltet (Best\u00e4llningsanteckningar) vilken\/vilka kul\u00f6rer du \u00f6nskar best\u00e4lla<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":" Ett enstaka uppm\u00e5lat kul\u00f6rprov p\u00e5 en av v\u00e5ra standardkul\u00f6rer.<\/p>\n V\u00e4lj antal kul\u00f6rprov du vill best\u00e4lla och l\u00e4gg i varukorgen.<\/p>\n N\u00e4r du sen kommer till kassan.<\/strong><\/p>\n Skriv i kommentarsf\u00e4ltet (Best\u00e4llningsanteckningar) vilken\/vilka kul\u00f6rer du \u00f6nskar best\u00e4lla<\/strong><\/p>\n","protected":false},"featured_media":75463,"comment_status":"open","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_members_access_role":[],"_members_access_error":""},"product_brand":[],"product_cat":[797,792,803],"product_tag":[],"class_list":["post-75681","product","type-product","status-publish","has-post-thumbnail","product_cat-linoljefarg-inomhus","product_cat-linoljefarg","product_cat-penslar-och-tillbehor","first","instock","taxable","shipping-taxable","purchasable","product-type-simple"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gysinge.com\/en\/wp-json\/wp\/v2\/product\/75681","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gysinge.com\/en\/wp-json\/wp\/v2\/product"}],"about":[{"href":"https:\/\/www.gysinge.com\/en\/wp-json\/wp\/v2\/types\/product"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gysinge.com\/en\/wp-json\/wp\/v2\/comments?post=75681"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gysinge.com\/en\/wp-json\/wp\/v2\/media\/75463"}],"wp:attachment":[{"href":"https:\/\/www.gysinge.com\/en\/wp-json\/wp\/v2\/media?parent=75681"}],"wp:term":[{"taxonomy":"product_brand","embeddable":true,"href":"https:\/\/www.gysinge.com\/en\/wp-json\/wp\/v2\/product_brand?post=75681"},{"taxonomy":"product_cat","embeddable":true,"href":"https:\/\/www.gysinge.com\/en\/wp-json\/wp\/v2\/product_cat?post=75681"},{"taxonomy":"product_tag","embeddable":true,"href":"https:\/\/www.gysinge.com\/en\/wp-json\/wp\/v2\/product_tag?post=75681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}