猿问

在 WooCommerce 中为库存可用性显示图标而不是文本

您解析收到的 JSON 两次。通过您的$.each调用,您可以遍历对象并尝试解析每个对象键的值。在第一次迭代中,使用您的示例数据,您尝试将“1_5cdb7ad317291.jpeg”解析为 JSON,这不是有效的 JSON。因此,您可以在第一次解析后访问该值。


$("[id^='deleteNotes']").click(function() {

        var id = $(this).closest('div').attr('id');

        console.log(id);

        $.ajax({

            url: "ajax/deleteidentifier.php",

            type: "post",

            data: {

                id_delete: id

            }

        })

        .done(function(result_query_sql_deletedStatus_notes){

            var data = JSON.parse(result_query_sql_deletedStatus_notes);

            if (data.deleted_status == "n") { //the cursor points me here. precisely, at the end of JSON and start of .parse

                alert("Moved to deleted folder.");

                window.location.reload();

            } else {

                alert("Note permanently deleted!");

                window.location.reload();

            }

        });

    });


泛舟湖上清波郎朗
浏览 110回答 1
1回答

BIG阳

根据嵌入在 WooCommerce 中的 Fontawesome 图标,尝试以下操作:add_filter( 'woocommerce_get_availability', 'dispay_custom_icons_for_availability', 1, 2);function dispay_custom_icons_for_availability( $availability, $product ) {&nbsp; &nbsp;global $product;&nbsp; &nbsp;// available&nbsp; &nbsp; if ( $product->is_in_stock() ) {&nbsp; &nbsp; &nbsp; &nbsp; $availability['availability'] = '<i class="fa fa-lg fa-smile" style="color:green;"></i>';&nbsp; &nbsp; &nbsp; &nbsp; $availability['class'] = 'in_stock';&nbsp; &nbsp; }&nbsp; &nbsp; // middle stock&nbsp; &nbsp; if ( $product->is_in_stock() && $product->get_stock_quantity() <= 20 ) {&nbsp; &nbsp; &nbsp; &nbsp; $availability['availability'] = '<i class="fa fa-lg fa-meh" style="color:orange;"></i>';&nbsp; &nbsp; &nbsp; &nbsp; $availability['class'] = 'low_stock';&nbsp;}&nbsp; &nbsp;// out of stock&nbsp; &nbsp; if ( ! $product->is_in_stock() ) {&nbsp; &nbsp; &nbsp; &nbsp; $availability['availability'] = '<i class="fa fa-lg fa-frown" style="color:red;"></i>';&nbsp; &nbsp; &nbsp; &nbsp; $availability['class'] = 'out_of_stock';&nbsp; &nbsp; }&nbsp; &nbsp; return $availability;}代码位于活动子主题(或活动主题)的 functions.php 文件中。测试和工作。您将获得以下图标之一
随时随地看视频慕课网APP
我要回答