【问题标题】:Display woocommerce sale end date显示 woocommerce 销售结束日期
【发布时间】:2014-04-27 21:54:03
【问题描述】:

我在 wordpress 中找到了这个帖子 http://wordpress.org/support/topic/get-woocommerce-scheduled-sale-end-date?replies=15

但是当我尝试它时,它不起作用。也许是因为答案太旧了。

有人知道如何获取预定销售 woocommerce 产品的结束日期吗?

这是我目前所拥有的

$sale_price_dates_to    = ( $date = get_post_meta( $thepostid, '_sale_price_dates_to', true ) ) ? date_i18n( 'Y-m-d', $date ) : '';
echo $sale_price_dates_to;

返回

string(0) ""

谢谢

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    this 页面上的示例,详细说明如何完成:
    将以下内容添加到functions.php 文件中

    add_filter( 'woocommerce_get_price_html', 'custom_price_html', 100, 2 );
    function custom_price_html( $price, $product )
    {
        global $post;
        $sales_price_to = get_post_meta($post->ID, '_sale_price_dates_to', true);
        if(is_single() && $sales_price_to != "")
        {
            $sales_price_date_to = date("j M y", $sales_price_to);
            return str_replace( '</ins>', ' </ins> <b>(Offer till '.$sales_price_date_to.')</b>', $price );
        }
        else
        {
            return apply_filters( 'woocommerce_get_price', $price );
        }
    }
    

    我已经在我的网站上尝试过,它对我有用。

    【讨论】:

    • 看起来这对于默认的单个产品页面来说是一个很好的解决方案。好的!但是,我需要将日期与销售价格分开显示。
    • 我怎么能把日期格式变成西班牙语,这很好用。谢谢
    【解决方案2】:

    这对我有用:)

        $thepostid = get_the_ID();
        $sale_price_dates_to    = ( $date = get_post_meta( $thepostid, '_sale_price_dates_to', true ) ) ? date_i18n( 'Y-m-d', $date ) : '';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-26
      • 2021-05-18
      • 1970-01-01
      • 2022-09-28
      • 2018-07-30
      • 1970-01-01
      • 1970-01-01
      • 2017-07-13
      相关资源
      最近更新 更多