1 回答

TA貢獻1828條經驗 獲得超3個贊
您可以使用將在每個掛鉤函數上調用的自定義函數,例如:
// Custom function that handle the code to display a product attribute?
function custom_display_attribute( $product, $taxonomy = 'pa_delivery') {
? ? $value = $product->get_attribute( $taxonomy );
? ? if ( ! empty($value) && $product->is_in_stock() ) {
? ? ? ? $label = wc_attribute_label( $taxonomy );
? ? ? ? echo '<small>' . $label . ': ' . $value . '</small>';
? ? }
}
// On product archive pages
add_action( 'woocommerce_after_shop_loop_item', 'product_attribute_delivery_archives', 1 );
function product_attribute_delivery_archives() {
? ? global $product;
? ? custom_display_attribute( $product );
? ? // When product is out of stock displays "Sold Out"
? ? if ( ! $product->is_in_stock() ) {
? ? ? ? echo __("Sold Out", "woocommerce");
? ? }
}
// On product single pages
add_action( 'woocommerce_single_product_summary', 'product_attribute_delivery_single', 27 );
function product_attribute_delivery_single() {
? ? global $product;
? ? custom_display_attribute( $product );
}
// On orders and email notifications
add_action('woocommerce_order_item_meta_end', 'custom_item_meta', 10, 4 );
function custom_item_meta( $item_id, $item, $order, $plain_text ) {? ?
? ? custom_display_attribute( wc_get_product( $item->get_product_id() ) );
}
它應該有效。
只有當產品沒有庫存時,存檔頁面才會顯示“已售完”。
- 1 回答
- 0 關注
- 110 瀏覽
添加回答
舉報