第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

處理 Woocommerce 上的產(chǎn)品類型

處理 Woocommerce 上的產(chǎn)品類型

PHP
Qyouu 2023-05-26 16:16:57
如果我嘗試以這種方式獲取產(chǎn)品類型,我真的很困惑如何在 Woocommerce 中正確獲取產(chǎn)品類型:$product->get_type();simple即使產(chǎn)品是可變的,它也總是返回,然后我嘗試了以下操作:$terms = get_the_terms($this->product->get_id(), 'product_type');$product_type = (!empty($terms)) ? sanitize_title(current($terms)->name) : 'simple';從上面的代碼可以看出,它獲取了product_type產(chǎn)品的分類法,如果存在則返回分類法名稱,否則返回simple。然而,即使產(chǎn)品是可變的,它仍然會返回simple,我現(xiàn)在不知道該怎么辦,因為我從 woocommerce 掛鉤的參數(shù)中獲取產(chǎn)品對象,我不知道它是什么類型的產(chǎn)品,我需要制作這個驗證。如何正確獲取woocommerce中的產(chǎn)品類型?更新根據(jù)要求,我將添加我使用的完整代碼,這樣您就可以更好地了解我想要實現(xiàn)的目標?;旧衔蚁朐谟唵涡许椖抗芾砭庉嬈聊恢袑⒃侄物@示為一列。add_action( 'woocommerce_admin_order_item_values', bani_add_cost_price_column_order_value_admin_edit', 10, 3);function ebani_add_cost_price_column_order_value_admin_edit( $product, $item, $item_id ) {        $order = $item->get_order();        ?>    <td class="item_cost_price" width="1%" data-sort-value="<?php echo esc_attr( $order->get_item_subtotal( $item, false, true ) ); ?>">        <div class="view">            <?php            if( ! is_null( $product ) ){                                //The right way to get the product type                $terms = get_the_terms( $product->get_id(), 'product_type' );                $product_type = ( !empty( $terms ) ) ? sanitize_title( current( $terms )->name ) : 'simple';                echo $product_type;                if( $product_type == 'variable' ) {                    $variation_id = $item->get_variation_id();                    echo wc_price( get_post_meta( $variation_id, 'variation_cost', true ), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped                }elseif( $product_type == 'simple' ) 
查看完整描述

1 回答

?
30秒到達戰(zhàn)場

TA貢獻1828條經(jīng)驗 獲得超6個贊

我不是很明白get_the_terms.?get_type()應該足夠了。


// Add header

function action_woocommerce_admin_order_item_headers( $order ) {

? ? echo '<th class="line_mytitle sortable" data-sort="your-sort-option">My Title</th>';

}

add_action( 'woocommerce_admin_order_item_headers', 'action_woocommerce_admin_order_item_headers', 10, 1 );


//Add content

function action_woocommerce_admin_order_item_values( $product, $item, $item_id ) {

? ? $order = $item->get_order();


? ? ?>

? ? <td class="item_cost_price" width="1%" data-sort-value="<?php echo esc_attr( $order->get_item_subtotal( $item, false, true ) ); ?>">

? ? ? ? <div class="view">

? ? ? ? ? ? <?php

? ? ? ? ? ? if( ! is_null( $product ) ) {

? ? ? ? ? ? ? ? // Get product type

? ? ? ? ? ? ? ? $product_type = $product->get_type();


? ? ? ? ? ? ? ? echo 'product type = ' . $product_type . '<br>';


? ? ? ? ? ? ? ? if( $product_type == 'variation' ) {

? ? ? ? ? ? ? ? ? ? $variation_id = $item->get_variation_id();

? ? ? ? ? ? ? ? ? ? echo wc_price( get_post_meta( $variation_id, 'variation_cost', true ), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

? ? ? ? ? ? ? ? } elseif( $product_type == 'simple' ) {

? ? ? ? ? ? ? ? ? ? echo wc_price( get_post_meta( $item->get_product_id(), 'cost_price', true ), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

? ? ? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? ? ? echo "No aplica";

? ? ? ? ? ? ? ? }

? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? echo 'No aplica';

? ? ? ? ? ? }

? ? ? ? ? ? ?>

? ? ? ? </div>

? ? </td>

? ? <?php

}

add_action( 'woocommerce_admin_order_item_values', 'action_woocommerce_admin_order_item_values', 10, 3 );



查看完整回答
反對 回復 2023-05-26
  • 1 回答
  • 0 關注
  • 110 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號