Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WooCommerce-Can';t添加一个<;span>;返回内部_Php_Wordpress_Woocommerce - Fatal编程技术网

Php WooCommerce-Can';t添加一个<;span>;返回内部

Php WooCommerce-Can';t添加一个<;span>;返回内部,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我正在使用以下代码更改WooCommerce中的“添加到购物车”按钮文本 add_filter( 'woocommerce_product_add_to_cart_text', 'custom_add_to_cart_price', 20, 2 ); // Shop and other archives pages add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_add_to_cart_price', 20,

我正在使用以下代码更改WooCommerce中的“添加到购物车”按钮文本

add_filter( 'woocommerce_product_add_to_cart_text', 'custom_add_to_cart_price', 20, 2 ); // Shop and other archives pages
add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_add_to_cart_price', 20, 2 ); // Single product pages
function custom_add_to_cart_price( $button_text, $product ) {
    // Variable products
    if( $product->is_type('variable') ) {
        // shop and archives
        if( ! is_product() ){

            $product_price = wc_price( wc_get_price_to_display( $product, array( 'price' => $product->get_variation_price() ) ) );
            return strip_tags( $product_price ) . ' — ' . $button_text;
        }
        // Single product pages
        else {
            $variations_data =[]; // Initializing

        // Loop through variations data
        foreach($product->get_available_variations() as $variation ) {
            // Set for each variation ID the corresponding price in the data array (to be used in jQuery)
            $variations_data[$variation['variation_id']] = $variation['display_price'];
        }
        ?>
        <script>
        jQuery(function($) {
            var jsonData = <?php echo json_encode($variations_data); ?>,
                inputVID = 'input.variation_id';

            $('input').change( function(){
                if( '' != $(inputVID).val() ) {
                    var vid      = $(inputVID).val(), // VARIATION ID
                       vprice   = ''; // Initilizing

                    // Loop through variation IDs / Prices pairs
                    $.each( jsonData, function( index, price ) {
                        if( index == $(inputVID).val() ) {
                            vprice = Math.round(price); // The right variation price
                        }
                    });
                    // Change price dynamically when changing options
                    $( "button.single_add_to_cart_button.button.alt span" ).remove();
                    $(".single_add_to_cart_button").prepend("<span>" + "$" + vprice + " — " + "</span>");
                }
            });
        });
        </script><?php
            return $button_text;
        }
    }
    // All other product types
    else {
        $product_price = wc_price( wc_get_price_to_display( $product ) );
        return strip_tags( $product_price ) . ' — ' . $button_text;
    }
}
我试图在输出的HTML中添加一个
,但它不包括


我已经试了好几个小时试图找出原因

任何帮助都将不胜感激


感谢

这是由strip_标签功能引起的,有关其用法,请参见

当您使用某些现有答案代码时,请在您的问题中添加链接…您好,如果将来链接出现问题,请提供具体参考:strip_标签(字符串、允许的_标签)等。
返回strip_标签($product_price,”) . ' — ' . $按钮文本;带标签($input,
@Coll谢谢你,notedFantastic!这是非常有效的。非常感谢你这么快回答。
$product_price = wc_price( wc_get_price_to_display( $product ) );
return strip_tags( $product_price ) . ' — ' . $button_text;
<a href="?add-to-cart=148">&lt;span&gt;$25.00 —  &lt;/span&gt;Add to cart</a>