作为一个新手,我希望我以正确的格式发布这篇文章.我熟悉WordPress,但对PHP非常陌生.
The Concept: 使用自定义字段(course_content_page_url)将页面链接添加到产品中.一旦进行了购买并在"帐户"页面上生成了订单,该字段将被添加到订单页面.然后,一列显示此URL,允许用户从仪表板访问它.
我已经创建了一个WooCommerce产品,其中有一个使用ACF的自定义字段.此自定义字段数据需要显示在"帐户"页面上的订单选项卡下的新列中.我已经设法创建了一个列并将其链接到我的自定义字段,但它并不显示字段中的数据,默认值为"没有给定URL".
Here's the article I followed but it doesn't seem to be working for me.
add_filter( 'woocommerce_account_orders_columns', 'add_account_orders_column', 10, 1 );
function add_account_orders_column( $columns ){
$order_actions = $columns['order-actions']; // Save Order actions
unset($columns['order-actions']); // Remove Order actions
// Add your custom column key / label
$columns['course_content_page_url'] = __( 'Course URL', 'woocommerce' );
// Add back previously saved "Order actions"
$columns['order-actions'] = $order_actions;
return $columns;
}
// Display a custom field value from order metadata
add_action( 'woocommerce_my_account_my_orders_column_course_content_page_url', 'add_account_orders_column_rows' );
function add_account_orders_column_rows( $order ) {
// Example with a custom field
if ( $value = $order->get_meta( 'course_content_page_url' ) ) {
esc_html_e( $value );
} else {
printf( '<small>%s</small>', __("no url given") );
}
}
The screenshot:. Account dashboard with no value showing.
是否有任何方法可以将此自定义字段数据添加到订购邮箱中?