Skip to content

Instantly share code, notes, and snippets.

@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
@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 April 26, 2022 12:17
Fix-plus-minus-buttons for the theme Stoni
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 )
});
@marcusig
marcusig / add-script-after-configurator-start.js
Created March 22, 2022 05:08
Add a script after initialising / starting the configurator
wp.hooks.addAction( 'PC.fe.start', 'Custom_script', function( configurator ) {
// Do something here. E.g.:
// Get the viewer
var viewer = configurator.viewer.$el;
// Get the layer container
var layers_container = configurator.viewer.$( '.mkl_pc_layers' );
} );
@marcusig
marcusig / wrap-layer-images.js
Created March 19, 2022 08:19
Wrap layer images with a div. One div per layer
wp.hooks.addAction( 'PC.fe.viewer.item.added', 'MKL/PC/Custom_JS', function( view, viewer ) {
// Set the class name
var layer_class = 'layer-' + view.model.get( 'layerId' );
// Find the existing container.
var layer_container = viewer.$layers.find( '.' + layer_class );
if ( ! layer_container.length ) {
// If the container doesn't exist, add it
view.$el.wrap( '<div class="' + layer_class + '" />' );
} else {
layer_container.append( view.$el );