【问题标题】:Woocommerce hook after product is published产品发布后的 Woocommerce 挂钩
【发布时间】:2016-10-19 10:19:12
【问题描述】:

我在下面使用

add_action('transition_post_status', 'my_product_update', 1000, 3);

function my_product_update($new_status, $old_status, $post) {
    if($new_status == 'publish' && $post->post_type == "product") {
         $product_id = $post->ID;
         $product = new WC_Product($product_id);
         echo $product->get_price();
    }
}

我发现$product->get_price()string(0) ""
我认为这是因为我在保存之前检索了价格。
但我可以使用$product->post->post_title 检索名称

知道如何在产品发布后立即获得价格吗?

谢谢。

【问题讨论】:

    标签: wordpress woocommerce hook


    【解决方案1】:

    试试这个:

    function wpa104760_default_price( $post_id, $post ){  
        echo $price = get_post_meta( $post_id, '_regular_price', true);
        echo $sale = get_post_meta( $post_id, '_sale_price', true);
       // exit;
    
    }
    add_action( 'woocommerce_process_product_meta', 'wpa104760_default_price',1000,2 );
    

    【讨论】:

    • 感谢您的帮助,但它不起作用。结果还是一样。
    • @Tungshev 我已经更新了我的答案。这应该有效。谢谢。
    • 完美运行。你是天才。我真的很感激。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-21
    • 2021-07-10
    • 2021-06-09
    • 1970-01-01
    • 2021-12-03
    • 2018-12-06
    • 2017-07-02
    相关资源
    最近更新 更多