Last active
July 15, 2024 15:11
-
-
Save dantetesta/abcc241169e852f06426affb1fc664a8 to your computer and use it in GitHub Desktop.
PERMITE CRIAR UM INPUT COM INCREMENTO DE 6 EM 6 NOS PRODUTOS DA CATEGORIA BOLAS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USADO EM https://galeriacdsports.com.br/home/ | |
TRECHO JS/CSS | |
<script> | |
jQuery(document).ready(function() { | |
jQuery(document).on('input change', '.sn_qtd', function() { | |
var input = jQuery(this); | |
var step = parseInt(input.attr('step'), 10); | |
var value = parseInt(input.val(), 10); | |
if (step === 6 && value % 6 !== 0 && value !== 0) { | |
if (!input.data('alerted')) { | |
alert('O valor deve ser múltiplo de 6.'); | |
input.val(''); | |
input.data('alerted', true); | |
} | |
} else { | |
input.data('alerted', false); | |
} | |
}); | |
jQuery(document).on('focus', '.sn_qtd', function() { | |
var input = jQuery(this); | |
input.data('alerted', false); | |
}); | |
}); | |
</script> | |
<style> | |
.sn_qtd { | |
width: 100%; | |
max-width: 100px; | |
display: flex; | |
border: none; | |
border-radius: 5px !important; | |
font-family: "Poppins", sans-serif; | |
outline: none !important; | |
font-size: 16px; | |
} | |
</style> | |
Trecho PHP | |
// Adiciona o shortcode | |
function sn_qtd_shortcode() { | |
global $post; | |
// Verifica se o post atual pertence à categoria 'bolas' | |
$is_bolas = has_term('bolas', 'categorias-produto', $post->ID); | |
// Configura o incremento do input | |
$step = $is_bolas ? 6 : 1; | |
// Gera o HTML do input com o incremento apropriado | |
ob_start(); | |
?> | |
<input type="number" class="sn_qtd" size="2" min="0" step="<?php echo esc_attr($step); ?>"> | |
<?php | |
return ob_get_clean(); | |
} | |
add_shortcode('sn_qtd', 'sn_qtd_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment