Skip to content

Instantly share code, notes, and snippets.

@marcusig
marcusig / remove-html-from-config-export.php
Last active Nov 8, 2022
Remove HTML from the configuration export, and add the image link
View remove-html-from-config-export.php
<?php
// Trip the HTML from the configuration
add_filter( 'woe_get_order_product_value_Configuration', function( $value, $order, $item ) {
// Handle "dynamic data" orders
if ( strpos( $value, 'order-configuration-details' ) && function_exists( 'mkl_pc' ) && mkl_pc( 'admin' ) ) {
$meta = new stdClass();
$meta->value = $value;
$value = mkl_pc( 'admin' )->order->format_meta( $value, $meta, $item );
}
@marcusig
marcusig / execute-shortcodes-on-description.php
Created Oct 29, 2022
Execute shortcodes found in the description fields, by applying the WP filter 'the_content'
View execute-shortcodes-on-description.php
<?php
add_filter( 'mkl_product_configurator_get_front_end_data', function( $data ) {
// Filter the choices
if ( isset( $data['content'] ) && is_array( $data['content'] ) ) {
foreach( $data['content'] as $lin => $layer ) {
foreach( $layer['choices'] as $cin => $choice ) {
if ( isset( $choice['description'] ) ) {
$data['content'][$lin]['choices'][$cin]['description'] = apply_filters( 'the_content', $choice['description'] );
}
@marcusig
marcusig / bulk-increase-prices.js
Created Oct 28, 2022
Increase the prices in bulk, in the Bulk price edit screen
View bulk-increase-prices.js
var factor = 1.05;
var round = true;
jQuery( '.bulk-choice input.extra-price' ).each( function( ind, item ) {
if ( ! jQuery( item ).val() ) return;
var value = jQuery( item ).val() * factor;
if ( round ) value = Math.round( value );
jQuery( item ).val( value ).trigger( 'change' );
});
@marcusig
marcusig / filter-order-meta-for-rest-api.php
Last active Oct 26, 2022
Filter the rest api result when exporting orders, replacing the meta value by display_value, which stores the readable data.
View filter-order-meta-for-rest-api.php
<?php
add_filter( "woocommerce_rest_prepare_shop_order_object", function( $response, $object, $request ) {
foreach( $response->data['line_items'] as $ind => $item ) {
foreach( $item['meta_data'] as $md_ind => $meta_data ) {
// If the value contains order-configuration-details
if ( strpos( $meta_data['value'], 'order-configuration-details' ) ) {
// then replace the value by display_value
$response->data['line_items'][$ind]['meta_data'][$md_ind]['value'] = $meta_data['display_value'];
}
@marcusig
marcusig / make-everything-scroll-on-mobile.css
Created Oct 20, 2022
[Configurator] Make everything scroll on mobile
View make-everything-scroll-on-mobile.css
@media (max-width: 660px) {
.mkl_pc.opened .mkl_pc_container {
overflow: auto;
bottom: 4em;
}
.mkl_pc.opened .mkl_pc_container .mkl_pc_viewer {
position: relative;
height: calc(50vh - 60px);
bottom: auto;
top: 0;
@marcusig
marcusig / change-tooltip-duration.js
Last active Aug 23, 2022
[configurator] Change tooltip duration / delay
View change-tooltip-duration.js
// Change the tooltip. See the available options on https://atomiks.github.io/tippyjs/v6/all-props/#duration
wp.hooks.addFilter( 'PC.fe.tooltip.options', 'myDomain', function( options ) {
options.duration = [100, 400];
return options;
} );
@marcusig
marcusig / add-html-support-to-layer-name.php
Created Aug 23, 2022
[Configurator] add html support to layer name
View add-html-support-to-layer-name.php
<?php
// Add the new label, with html support: {{{ instead of {{
function my_prefix_frontend_configurator_layer_name() {
?>
<span class="text layer-name">{{{data.name}}}</span>
<?php
}
add_action( 'tmpl-mkl-pc-configurator-layer-item-button', 'my_prefix_frontend_configurator_layer_name', 10 );
@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);