Skip to content

Instantly share code, notes, and snippets.

@marcusig
marcusig / dark-mode-cross-to-arrow.css
Created August 4, 2022 06:35
Change the active layer close icon from a cross to an arrow
.mkl_pc .mkl_pc_container .mkl_pc_toolbar section.choices .layer_choices li.layer-choices-title > span a.close::before,
.mkl_pc .mkl_pc_container .mkl_pc_toolbar section.choices .layer_choices li.layer-choices-title > span a.close::after {
width: 15px;
transform-origin: 100%;
}
.mkl_pc .mkl_pc_container .mkl_pc_toolbar section.choices .layer_choices li.layer-choices-title > span a.close::after {
transform: translateX(8px) rotate(35deg);
}
@marcusig
marcusig / gtranslate-pro-editor-filter.php
Created July 29, 2022 14:34
Gtranslate Pro editor filter for the product configurator
<?php
add_filter( 'mkl_pc_get_configurator_data_js_output', function( $js, $id, $data ) {
if ( class_exists( 'GTranslate' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) {
$output = 'var PC = PC || {};'."\n";
$output .= 'PC.productData = PC.productData || {};'."\n";
// Add compatibility with GTranslate premium, enabling users to manually update translations.
$output .= "fetch('/wp-admin/admin-ajax.php?action=pc_get_data&data=init&fe=".$_REQUEST['fe']."&id={$id}&ver=".time()."').then(r => r.json()).then(data => {PC.productData.prod_$id = data;});";
return $output;
}
@marcusig
marcusig / float-open-layers.css
Created July 6, 2022 05:43
Keep all layers opened (Float / WSB themes)
.mkl_pc .mkl_pc_container .mkl_pc_toolbar section.choices ul.layer_choices:not(.display-mode-dropdown) {
display: block !important;
}
.mkl_pc .mkl_pc_container .mkl_pc_toolbar section.choices .layers button.layer-item::after{
display: none;
}
.mkl_pc .mkl_pc_container .mkl_pc_toolbar section.choices .layers button.layer-item::before{
width: calc( 100% - 1em);
@marcusig
marcusig / export-order-data.php
Created June 27, 2022 13:03
Export configuration data on separate lines - starting point
<?php
add_filter( "woe_fetch_order_products", function ($products, $order, $labels, $format, $static_vals) {
foreach( $order->get_items('line_item') as $pos => $item) {
if ( $config_data = $item->get_meta( '_configurator_data' ) ) {
foreach( $config_data as $selection ) {
// Get the item name. E.g. Farve, or Vaelg overdel
$layer_name = $selection->get_layer( 'name' );
// Get the item's selected choice. E.g. Lady top loose
$choice_name = $selection->get_choice( 'name' );
@marcusig
marcusig / add-group-name.php
Last active June 18, 2022 12:11
Add the group name in the cart and order
<?php
// Filter the data in the cart / checkout
add_filter( 'mkl_pc/wc_cart_get_item_data/choice', function( $choice_data, $layer ) {
$parent_id = $layer->get_choice( 'parent' );
if ( $parent_id && is_callable( [ $layer, 'get_choice_by_id' ] ) ) {
$parent = $layer->get_choice_by_id( $parent_id );
if ( $parent && isset( $parent[ 'name' ] ) ) {
$choice_data['value'] = $parent[ 'name' ] . ', ' . $choice_data['value'];
}
}
@marcusig
marcusig / divi-calculate-totals.php
Created June 1, 2022 14:25
Fix the total calculation in Divi, when using the Cart Products module
<?php
add_action( 'woocommerce_before_cart', function() {
WC()->cart->calculate_totals();
} );
@marcusig
marcusig / get-configurator-colors.php
Created May 18, 2022 17:01
Get colors from a product's configurator data
<?php
/**
* Get the hex colors from a product's configurator data
*
* @param int $product_id
* @return array
*/
function get_product_colors_from_configuration( $product_id ) {
$colors = [];
@marcusig
marcusig / move-syd-button.php
Created May 18, 2022 16:24
Move the Save your design button to the sidebar
<?php
// Hook before the templates are included
add_action( 'mkl_pc_frontend_templates_before', function() {
// Get the SYD instance
$save_your_design = mkl_pc()->get_extension( 'save-your-design' );
if ( ! $save_your_design ) return;
// Remove the original button
remove_action( 'mkl_pc_frontend_configurator_footer_section_right_before', array( $save_your_design->product, 'add_configurator_button' ), 20 );
// Add the original button in the toolbar instead
@marcusig
marcusig / float-show-price-and-add-to-cart-on-mobile.css
Last active May 16, 2022 05:38
FLOAT - Show price and add to cart on mobile
@media (max-width: 660px) {
.mkl_pc .mkl_pc_container .mkl-pc-show-form {
display: none;
}
.mkl_pc .mkl_pc_container footer .form.form-cart {
position: relative;
padding: 0;
background: transparent;
box-shadow: none;
border-radius: 0;
@media (max-width: 660px) {
.mkl_pc .mkl_pc_container .mkl-pc-show-form {
display: none;
}
.mkl_pc .mkl_pc_container footer .form.form-cart {
position: relative;
padding: 0;
background: transparent;
box-shadow: none;
border-radius: 0;