Skip to content

Instantly share code, notes, and snippets.

@marcusig
marcusig / gamepcbestel.nl-tweaks.css
Last active February 26, 2022 05:40
CSS tweaks for gamepcbestel.nl
@media(min-width: 1000px) {
.mkl_pc {
/* Change this value to change the sidebar width */
--toolbar_width: 500px;
}
}
.mkl_pc .mkl_pc_container .mkl_pc_toolbar section.choices .layers button {
white-space: normal;
word-break: break-word;
@marcusig
marcusig / be-your-bag-tweaks.css
Created January 11, 2022 09:25
Be-your-bag tweaks
@media(max-width: 660px) {
.mkl_pc .mkl_pc_container footer button.configurator-add-to-cart span {
display: block;
}
button.primary.button.btn.btn-primary.configurator-add-to-cart {
background-color: #3bb54a !important;
margin-right: 4px;
}
@marcusig
marcusig / current-layer-only.css
Created January 12, 2022 15:44
Only show the image of the currently opened layer
.mkl_pc .mkl_pc_container .mkl_pc_viewer .mkl_pc_layers *:not(.current_layer) {
opacity: 0;
}
@marcusig
marcusig / action-on-choice-change.js
Created January 17, 2022 12:50
JS Action to execute code when a choice is changed.
// Requires wp.hooks
// Make sure to set 'wp-hooks' and 'jquery' as dependencies when loading this script.
if ( ! wp || ! wp.hooks ) return;
( function( $ ) {
wp.hooks.addAction( 'PC.fe.choice.set_choice', 'Custom_domain', function( model, view ) {
// Do something here.
// view.$el will give you the jQuery object of the current choice.
} );
@marcusig
marcusig / add-sku-to-button.php
Created January 17, 2022 14:29
Add SKU to the choice button
<?php
add_filter( 'tmpl-pc-configurator-choice-item-label', function( $label ) {
return $label . ' <# if ( data.sku ) { #><span class="sku">{{data.sku}}</span><# } #>';
} );
@marcusig
marcusig / order_received_item_thumbnail_image.php
Created January 20, 2022 05:06
Add the configuration image to the order received item
<?php
/**
* Display the product thumbnail in order received page
*/
function order_received_item_thumbnail_image( $item_name, $item, $is_visible ) {
// Targeting order received page only
if( ! is_wc_endpoint_url('order-received') ) return $item_name;
@marcusig
marcusig / remove-configurable-plugin-from-cart.php
Created January 28, 2022 09:56
Remove configurable product from the cart
<?php
add_action( 'mkl_pc/added_linked_product_to_the_cart', function( $cart_item_key, $product_id ) {
WC()->cart->remove_cart_item( $cart_item_key );
// Add custom notice
wc_add_notice( '<a href="' . esc_url( wc_get_cart_url() ) . '" class="button wc-forward">' . esc_html__( 'View cart', 'woocommerce' ) . '</a>' . __(' Your dress design has been added to your cart.', 'product-configurator-custom-theme') );
// Prevent default notice
throw new Exception();
}, 20, 2 );
@marcusig
marcusig / ocean-wp-qty-buttons.php
Last active February 12, 2022 18:37
OceanWP add QTY buttons to the configurator
<?php
add_action( 'wp_enqueue_scripts', function() {
wp_add_inline_script( 'mkl_pc/js/product_configurator', "
// When the configurator starts, add the qty buttons
wp.hooks.addAction( 'PC.fe.start', 'MKL/PC/Conditional', function() {
if ( 'undefined' != typeof oceanwpWooCustomFeatures && oceanwpWooCustomFeatures.quantityButtons ) oceanwpWooCustomFeatures.quantityButtons.start();
}, 30 );
" );
@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 );
@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' );
} );