Un utente ha chiesto
Categoria: Price Based on Country for WooCommerce di WordPress
Domanda: ajax (per la cache) tira l’hook woocommerce_get_price_html due volte
Buongiorno
Sto usando “Carica il prezzo del prodotto in background” per il supporto della cache.
Uso anche il gancio woocommerce woocommerce_get_price_html
Questo hook si attiva due volte e la mia tabella dei prezzi non viene visualizzata correttamente
Hai una soluzione ?
Ecco gli estratti
add_filter (‘woocommerce_get_price_html’, ‘filter_get_price_html’, 1000, 2);
/**
* Aggrappati al filtro woocommerce_get_price_html.
*
* @param $ prezzo
* @param $ _prodotto
* @ stringa di ritorno
* /
function filter_get_price_html ($ prezzo, $ _prodotto) {
if (! $ _ prodotto) {
restituire il prezzo $;
}
if (is_admin ()) {
restituire il prezzo $;
}
$ woocommerce globale;
if (get_option (‘woocommerce_t4m_remove_discount_on_coupon’, ‘yes’) == ‘yes’ &&! (empty ($ woocommerce-> cart-> apply_coupons))) {
restituire il prezzo $;
}
/ *
if ($ this-> coupon_check ()) {
restituire il prezzo $;
}
* /
if (get_post_meta ($ _product-> id, “_bulkdiscount_enabled”, true)! = “&& get_post_meta ($ _product-> id,” _bulkdiscount_enabled “, true)! == ‘yes’) {
restituire il prezzo $;
}
$ bulkDiscountType = get_option (‘woocommerce_t4m_discount_type’, ”);
/ * if ($ bulkDiscountType == ‘flat’) {
eco ‘
Sconto forfettario all’ingrosso
‘;
} else if ($ bulkDiscountType == ‘fisso’) {
eco ‘
Sconto di gruppo fisso
‘;
} Altro {
eco ‘
Percentuale di sconto all’ingrosso
‘;
}
* /
// ottieni la tabella degli sconti
$origPrice = $ _product-> get_price ();
// eco “
Prezzo originale = $origPrice
“;
$q = matrice (0.0);
$ d = matrice (0.0);
$ listino prezzi = array (0.0);
$ foundPriceBreak = FALSO;
$ product_id = $ _product-> get_id ();
// eco “
ID prodotto = $ product_ID
“;
/*approfitta di tutti gli sconti possibili*/
for ($ i = 1; $ i <= 5; $ i ++) {
array_push ($ q, get_post_meta ($ product_id, “_bulkdiscount_quantity_ $ i”, true));
if ($ bulkDiscountType == ‘flat’) {
array_push ($ priceList, get_post_meta ($ product_id, “_bulkdiscount_discount_flat_ $ i”, true)? get_post_meta ($ product_id, “_bulkdiscount_discount_flat_ $ i”, true): 0.0);
} else if ($ bulkDiscountType == ‘fisso’) {
array_push ($ d, get_post_meta ($ product_id, “_bulkdiscount_discount_fixed_ $ i”, vero)? get_post_meta ($ product_id, “_bulkdiscount_discount_fixed_ $ i”, vero): 0.0);
array_push ($ priceList, $ origPrice – $ d[$i] );
} Altro {
array_push ($ d, get_post_meta ($ product_id, “_bulkdiscount_discount_ $ i”, true)? get_post_meta ($ product_id, “_bulkdiscount_discount_ $ i”, true): 0.0);
array_push ($ priceList, $ origPrice * min (1.0, max (0, (100.0 – round ($ d[$i], 2)) / 100.0)));
}
}
$ tabellaprezzo = <<
Quantità | Prezzo |
---|---|
1 | $ prezzo |
$ q[$j] | “.wc_price ($ priceList[$j]); if ($ bulkDiscountType == ‘flat’) { $ priceTable = “sconto”; } $ tabellaprezzo. = “ |
non” ;
/ * if (è_prodotto ()) {
if ($ trovatoPriceBreak) {
return $ priceTable;
}
restituire il prezzo $;
}
elseif (is_shop()) {
if ($ trovatoPriceBreak) {
return $ priceTable;
}
restituire il prezzo $;
} * /
if ($ trovatoPriceBreak) {
return $ priceTable;
} Altro {
restituire il prezzo $;}
}
La pagina per cui ho bisogno di aiuto: [log in to see the link]
-
Autore del plugin
(@oscargare)
Ciao,
cambia la priorità in -1:
add_filter( ‘woocommerce_get_price_html’, ‘filter_get_price_html’, -1, 2);
(@roryrory)
Grazie mólto.
funziona benissimo!!(@roryrory)
Ciao
Tuttavia, sto riscontrando il problema in una singola pagina del prodotto
https://www.genimal.com/DNA/product/dna-sexing/Un’idea?
grazieAutore del plugin
(@oscargare)
Ciao,
Penso che tu stia generando un cattivo codice HTML includendo un tagall’interno di
https://stackoverflow.com/questions/10086912/why-is-table-not-allowed-inside-p
<p class="price"><span class="wcpbc-price wcpbc-price-57 loading" data-product-id="57"><table class="woocommerce-bulk-pricing-table">.....
il codice html sbagliato fa funzionare correttamente javascript.
Hai risolto il tuo problema?
0 / 0