Skip to content

Instantly share code, notes, and snippets.

@marcusig
marcusig / dark-mode-cross-to-arrow.css
Created Aug 4, 2022
Change the active layer close icon from a cross to an arrow
View dark-mode-cross-to-arrow.css
.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 Jul 29, 2022
Gtranslate Pro editor filter for the product configurator
View gtranslate-pro-editor-filter.php
<?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 Jul 6, 2022
Keep all layers opened (Float / WSB themes)
View float-open-layers.css
.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 Jun 27, 2022
Export configuration data on separate lines - starting point
View export-order-data.php
<?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 Jun 18, 2022
Add the group name in the cart and order
View add-group-name.php
<?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 Jun 1, 2022
Fix the total calculation in Divi, when using the Cart Products module
View divi-calculate-totals.php
<?php
add_action( 'woocommerce_before_cart', function() {
WC()->cart->calculate_totals();
} );
@marcusig
marcusig / get-configurator-colors.php
Created May 18, 2022
Get colors from a product's configurator data
View get-configurator-colors.php
<?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
Move the Save your design button to the sidebar
View move-syd-button.php
<?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
View H-show-price-and-add-to-cart-on-mobile.css
@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;
@marcusig
marcusig / fix-plus-minus-buttons.js
Created Apr 26, 2022
Fix-plus-minus-buttons for the theme Stoni
View fix-plus-minus-buttons.js
jQuery('body').on('click', '.quantity.number-input span.plus, .quantity.number-input span.minus', function(e){
setTimeout( function() {
jQuery( this.parentNode ).find( 'input[type=number]' ).trigger( 'change' );
}.bind( this ), 20 )
});