admin管理员组

文章数量:1302937

I want to get the value of a select attribute in the checkout page on WooCommerce, and then use it to show or not the delivery data.

I have tried everything but it still does not appear, the object of my products when I go through it comes out empty.

I have tried something similar to this to see what data I am getting but it comes out empty:

add_filter( 'woocommerce_cart_item_name', 'cart_variation_description', 20, 3);
function cart_variation_description( $name, $cart_item, $cart_item_key ) {
    // Get the corresponding WC_Product
    $product_item = $cart_item['data'];

    if(!empty($product_item) && $product_item->is_type( 'variation' ) ) {
        // WC 3+ compatibility
        //$descrition = $product_item->get_description();
        //$descrition = $product_item->get_attribute( 'pa_modo' );
        $descrition = $product_item->get_post_meta( $variation->ID, 'price_1_50', true );
        $result = __( 'Description: ', 'woocommerce' ) . $descrition;
        return $name . '<br>' . $result;
    } else
        return $name;
}

Thanks a lot.

本文标签: