[英]Wordpress, PHP - how to correctly add a function with filters
我正在使用 WC Vendors Woocommerce 插件,該插件使用以下代碼片段以在供應商前端儀表板中顯示“產品狀態”:
/**
* Product status text for output on front end.
*/
public static function product_status( $status ) {
$product_status = apply_filters(
'wcv_product_status',
array(
'publish' => __( 'Online', 'wcvendors-pro' ),
'future' => __( 'Scheduled', 'wcvendors-pro' ),
'draft' => __( 'Draft', 'wcvendors-pro' ),
'pending' => __( 'Pending Approval', 'wcvendors-pro' ),
'private' => __( 'Admin Only', 'wcvendors-pro' ),
'trash' => __( 'Trash', 'wcvendors-pro' ),
)
);
return $product_status[ $status ];
} // product_status()
我創建了一個額外的自定義帖子狀態“已退款”,我想將此自定義狀態添加到現有狀態。
所以我試圖利用過濾器'wcv_product_status'
來創建一個 function 來添加我的新產品狀態。
我的編碼知識真的很差,我只是在努力完成我的代碼片段。
這就是我目前擁有的:
add_filter( 'wcv_product_status', 'refunded_product_status' );
function refunded_product_status( $status ) {
'refunded' => __( 'Refunded', 'wcvendors-pro' );
return $status;
}
我想我應該在我的代碼片段中的某個地方使用'product_status'
,但我如何將整個東西編譯在一起?
非常感謝任何提示。
您必須更改作為參數收到的現有數組並將其返回。
add_filter( 'wcv_product_status', 'refunded_product_status', 20, 1 );
function refunded_product_status( $status ) {
$status['refunded'] = __( 'Refunded', 'wcvendors-pro' );
return $status;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.