Display woocommerce sale end date

后端 未结 2 874
独厮守ぢ
独厮守ぢ 2021-01-14 22:33

I found this thread in wordpress http://wordpress.org/support/topic/get-woocommerce-scheduled-sale-end-date?replies=15

but when I tried it, it did not work. Perhaps

相关标签:
2条回答
  • 2021-01-14 23:01

    This works for me :)

        $thepostid = get_the_ID();
        $sale_price_dates_to    = ( $date = get_post_meta( $thepostid, '_sale_price_dates_to', true ) ) ? date_i18n( 'Y-m-d', $date ) : '';
    
    0 讨论(0)
  • 2021-01-14 23:06

    An example on this page, details how it can be done:
    Add the following to the functions.php file

    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 );
        }
    }
    

    I have tried it on my website and it works for me.

    0 讨论(0)
提交回复
热议问题