Skip to content

Instantly share code, notes, and snippets.

@marcusig
marcusig / override-product-image-with-preset-image.php
Last active April 4, 2024 13:47
Override product image when loading a preset
<?php
add_filter( 'wp_get_attachment_image', function( $html, $attachment_id, $size, $icon, $attr ) {
global $product;
static $doing_filter = false;
if ( $doing_filter ) return $html;
if ( ! isset( $_REQUEST[ 'load-preset' ] ) ) return $html;
$doing_filter = true;
$post = get_post( (int) $_REQUEST[ 'load-preset' ] );
.mkl_pc .mkl_pc_container .mkl_pc_viewer .mkl_pc_layers img.bezel:not(.active) {
transform: translateX(calc(-50% - 300px)) translateY(-50%);
}
.mkl_pc .mkl_pc_container .mkl_pc_viewer .mkl_pc_layers img.bezel.active ~ img.bezel:not(.active) {
transform: translateX(calc(-50% + 300px)) translateY(-50%);
}
@marcusig
marcusig / add-from-prefix-to-product-price.php
Created March 14, 2024 08:10
Add 'From ' to a configurable product price
<?php
// Add a filter to the price, adding 'From ' to the price of a configurable product
add_filter( 'woocommerce_get_price_html', 'mkl_add_price_prefix', 20, 2 );
function mkl_add_price_prefix( $price, $product ) {
if ( ! function_exists( 'mkl_pc_is_configurable' ) || ! mkl_pc_is_configurable( $product->get_id() ) ) return $price;
return 'À partir de ' . $price;
}
/* CREATE YOUR MAKI OR DONBURI */
.donburi-builder .mkl_pc .mkl_pc_container .mkl_pc_viewer {
display: none;
}
.donburi-builder .mkl_pc {
--toolbar_width: 100%;
--mkl_pc_color-toolbar_bg: #fafbfc;
--mkl_pc_color-primary: rgb(175 78 43);
--mkl_pc_color-primary_rgb: 175, 78, 43;
@marcusig
marcusig / botiga-fix-qty-input-layout.css
Created December 27, 2023 15:15
[THEME Fix] Botiga - quantity input in the configurator
.theme-botiga .mkl_pc .mkl_pc_container .form.form-cart .quantity {
width: auto;
display: inline-flex;
}
@media (max-width: 660px) {
.theme-botiga .mkl_pc .mkl_pc_container .form.form-cart .quantity {
height: 46px;
margin: 0;
margin-right: 5px;
@marcusig
marcusig / do-not-display-configurator-data.php
Created November 29, 2023 06:37
Do not display configurator data in the cart and order
<?php
add_action( 'mkl_pc_is_loaded', function() {
remove_filter( 'woocommerce_get_item_data', array( mkl_pc( 'frontend' )->cart, 'wc_cart_get_item_data' ), 10 );
});
add_filter( 'mkl_pc_cart_item_choice', function( $cc ) {
return '';
} );
@marcusig
marcusig / override-sku-in-wc-rest-api.php
Created November 20, 2023 14:39
Override an order line item's SKU using the compounded SKU when using WooCommerce's REST API
<?php
/**
* Filters the REST response for shop order object
*/
add_filter( 'woocommerce_rest_prepare_shop_order_object', function( $response ) {
if ( ! function_exists( 'mkl_pc' ) ) return $response;
$configurator = null;
if ( ! isset( $response->data['line_items'] ) ) return $response;
@marcusig
marcusig / backorder-stock-labels.php
Created October 13, 2023 06:08
Add labels for normal backorder and in stock products
add_action( 'tmpl-pc-configurator-choice-item--after', 'hexatac_add_choice_out_of_stock_label' );
function hexatac_add_choice_out_of_stock_label() {
echo ' <# if ( data.manage_stock && \'none\' !== data.manage_stock && 0 >= data.stock ) { #>
<# if ( data.wc_backorder && "yes" == data.wc_backorder ) { #>
<span class="out-of-stock backorder">Sur commande</span>
<# } #>
<# } else if ( data.manage_stock && \'none\' !== data.manage_stock && 0 < data.stock ) { #>
<span class="out-of-stock en-stock">En stock</span>
<# } #>';
}
@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 / add-cart-link.php
Created December 7, 2021 05:07
Add a link to the cart (quote)