add_action( 'woocommerce_before_add_to_cart_button', 'sizes_before_add_to_cart_button', 0 );
function sizes_before_add_to_cart_button() {
global $product;
// Only on simple products
if( ! $product->is_type('simple') ) return;
// When product sizes are available
if ( $sizes = $product->get_attribute( 'size' ) ) :
$sizes = explode(", ",$sizes);
echo '<div class="lisatiedot__size__select" id="product-size-field">
<label for="product-size">' . __('Valitse koko <br>') . '</label>
<select class="select__size" name="product-size" id="product-size">
<option value="">' . __("Choose your size") . '</option>';
foreach( $sizes as $size ){
echo '<option value="' . $size . '">' . $size . '</option>';
}
echo '</select>
</div><br>';
endif;
}
add_filter( 'woocommerce_add_to_cart_validation', 'filter_add_to_cart_validation', 10, 4 );
function filter_add_to_cart_validation( $passed, $product_id, $quantity, $variation_id = 0 ) {
$product = wc_get_product($product_id);
// Only on simple products and When product sizes are available
if( ! $product->is_type('simple') && ! $product->get_attribute( 'size' ) )
return $passed;
if( isset( $_POST['product-size'] ) && empty( $_POST['product-size'] ) ) {
wc_add_notice( __("Please choose your size.", "woocommerce" ), 'error' );
$passed = false;
}
return $passed;
}
add_filter( 'woocommerce_add_cart_item_data', 'add_size_to_cart_item_data', 10, 3 );
function add_size_to_cart_item_data($cart_item_data, $product_id, $variation_id ){
if( isset( $_POST['product-size'] ) ) {
$cart_item_data['product-size'] = esc_attr( $_POST['product-size'] );
}
return $cart_item_data;
}
add_filter( 'woocommerce_get_item_data', 'display_size_on_cart_item', 10, 2 );
function display_size_on_cart_item( $cart_item_data, $cart_item ) {
if ( isset( $cart_item['product-size'] ) ){
$cart_item_data[] = array(
'name' => __('Size'),
'value' => $cart_item['product-size'],
);
}
return $cart_item_data;
}
<form class="cart"
action="<?php echo esc_url( apply_filters( 'woocommerce_add_to_cart_form_action', $product->get_permalink() ) ); ?>"
method="post"
enctype='multipart/form-data'>
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<?php
do_action( 'woocommerce_before_add_to_cart_quantity' );
woocommerce_quantity_input( array(
'min_value' => apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ),
'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ),
'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( wp_unslash( $_POST['quantity'] ) ) : $product->get_min_purchase_quantity(), // WPCS: CSRF ok, input var ok.
) );
do_action( 'woocommerce_after_add_to_cart_quantity' );
?>
<button type="submit" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" class="single_add_to_cart_button button alt"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
</form>
<meta name="viewport" content="width=device-width, initial-scale=1">
<svg id="service-man" viewBox="0 0 300 300" width="100%" height="100%">
<g fill="none"><path fill="#E74825" d="M150.03 52.645v-.004c.014 0 .028.004.051.004V0c-42.19.004-75.758 34.202-75.758 76.387 0 17.719 8.488 38.257 18.613 51.218-16.332 6.244-25.937 12.008-34.103 19.213C44.413 159.542 30.97 175.653 31 228.953v72.356h119.054v-59.527H90.527c0-13.49-.47-25.686 1.624-36.238 2.665-13.366 11.68-35.915 57.914-35.915l.015-17.937v-43.075c-.023 0-.037.004-.052.004v-.007c-13.495-.083-25.095-15.907-25.095-30.141 0-14.233 10.873-25.768 25.096-25.828"></path><path fill="#CD965E" d="M150.107 52.645v-.004c-.014 0-.029.004-.052.004V0c42.19.004 76.962 34.202 76.962 76.387 0 17.719-8.488 38.257-18.612 51.218 16.33 6.244 25.936 12.008 34.101 19.213 11.867 10.469 21.568 23.19 25.343 57.09.815 7.302 1.26 15.589 1.26 25.045v46.844H150.056V216.29h59.528c0-3.846-.323-5.625-1.427-10.747-2.87-13.325-11.852-35.915-58.087-35.915l-.014-61.012c.022 0 .036.004.052.004v-.007c13.494-.083 26.3-15.907 26.3-30.141 0-14.233-12.077-25.768-26.3-25.828"></path>
</g>
</svg>
как быть с визуальными редакторами и кастомными полями, если на первых спрос больше, а более лёгкие в использовании вторые?
если в PSD макете есть шрифт