【问题标题】:Changing WooCommerce availability text and include the original HTML更改 WooCommerce 可用性文本并包含原始 HTML
【发布时间】:2018-05-28 12:15:18
【问题描述】:

这就是我现在拥有的:

文本未包含在标准 WooCommerce HTML 中。

这是我不想要的:

此处的文本正确地包含在标准 WooCommerce HTML 中。

这就是我所做的

我已将此添加到functions.php。我正在使用高级自定义字段,因此我将该字段的内容(纯文本)存储在 $availability 变量中。

add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
function wcs_custom_get_availability( $availability, $_product ) {
    // Change Out of Stock Text
    if ( ! $_product->is_in_stock() ) {
        $availability['availability'] = the_field("text_stock", "option");
    }
    return $availability;
}

文本正确显示在产品页面上,但没有输出通常包装库存信息的 HTML(在 WooCommerce/templates/single-product/stock.php 中找到)。 p>

我试过这个:

add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
function wcs_custom_get_availability( $availability, $_product ) {
    // Change Out of Stock Text
    if ( ! $_product->is_in_stock() ) {
        $availability['availability'] = '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . the_field("text_stock", "option") . '</p>';
    }
    return $availability;
}

但这给我留下了这个奇怪的输出:

我的问题

  • 如何仍能输出相同的 HTML?
  • 如果上述选项不可用,我如何输出自己的 HTML?

【问题讨论】:

    标签: php wordpress woocommerce wordpress-theming hook-woocommerce


    【解决方案1】:

    您是否尝试过get_field("text_stock", "option") 而不是the_field("text_stock", "option")

    【讨论】:

    • 没有。为什么我不... 因为那行得通。 面部护理。但是,它仍然会输出一个没有内容的额外段落,如上面的屏幕截图所示。
    • text_stock 是什么字段类型?某些字段类型会自动插入

      标签。

    • 这是普通的“文本”类型,它输出一个没有任何标签或 HTML 的字符串。只是纯文本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2019-03-29
    • 2021-03-17
    • 2013-09-22
    • 1970-01-01
    • 2020-04-26
    • 2021-11-30
    相关资源
    最近更新 更多