由于插件Essential Grid只是将产品标题传递给它的灯箱标题,以显示足够的产品描述,因此我不得不在Woocommerce商店中使用较长的产品标题。这些较长的标题依次在WooCommerce订单电子邮件中输出给客户,包括HTML标签-如下所示。
我已通过调用要输出的每种产品的simple_title自定义元而不是默认标题(已在我编辑的mini-cart.php中看到如下所示(***表示我的唯一更改)),在我的微型购物车模式中解决了此问题。
<?php
do_action( 'woocommerce_before_mini_cart_contents' );
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
***$meta_title = get_post_meta( $product_id, 'simple_title', true)***;
...
<?php echo str_replace( array( 'http:', 'https:' ), '', $thumbnail ) . ***$meta_title*** . ' '; ?>
我现在想在WooCommerce的email-downloads.php中实现相同的解决方案来修复我的Woocommerce电子邮件,但是我似乎无法在此文件的'foreach'中使'get_post_meta'工作。任何人都可以分享正确的格式,或者在下面的代码中将其插入哪里?
我至少将输出部分隔离到了
<?php echo esc_html( $download['product_name'] ); ?>
-此输出需要替换为显示产品的simple_title自定义元。
非常感谢您的任何想法。
<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; margin-bottom: 40px;" border="1">
<thead>
<tr>
<?php foreach ( $columns as $column_id => $column_name ) : ?>
<th class="td" scope="col" style="text-align:<?php echo $text_align; ?>;"><?php echo esc_html( $column_name ); ?></th>
<?php endforeach; ?>
</tr>
</thead>
<?php foreach ( $downloads as $download ) : ?>
<tr>
<?php foreach ( $columns as $column_id => $column_name ) : ?>
<td class="td" style="text-align:<?php echo $text_align; ?>;"><?php
if ( has_action( 'woocommerce_email_downloads_column_' . $column_id ) ) {
do_action( 'woocommerce_email_downloads_column_' . $column_id, $download );
} else {
switch ( $column_id ) {
case 'download-product' : ?>
<?php echo esc_html( $download['product_name'] ); ?>
<?php
break;
case 'download-file' : ?>
<a href="<?php echo esc_url( $download['download_url'] ); ?>" class="woocommerce-MyAccount-downloads-file button alt"><?php echo esc_html( $download['download_name'] ); ?></a>
<?php
break;
case 'download-expires' : ?>
<?php if ( ! empty( $download['access_expires'] ) ) : ?>
<time datetime="<?php echo date( 'Y-m-d', strtotime( $download['access_expires'] ) ); ?>" title="<?php echo esc_attr( strtotime( $download['access_expires'] ) ); ?>"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $download['access_expires'] ) ); ?></time>
<?php else : ?>
<?php _e( 'Never', 'woocommerce' ); ?>
<?php endif;
break;
}
}
?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>
有两种可能的方法:
1)使用此过滤器挂钩:
add_filter( 'woocommerce_order_get_downloadable_items', 'custom_order_get_downloadable_items', 30, 2 );
function custom_order_get_downloadable_items( $downloads, $orders ){
if( is_admin() )
$downloads['product_name'] = get_post_meta( $downloads['product_id'], 'simple_title', true );
return $downloads;
}
代码进入您的活动子主题(或活动主题)的function.php文件中。它应该工作。
2)通过主题直接覆盖模板并替换为emails/email-downloads.php
文件:
<?php echo esc_html( $download['product_name'] ); ?>
通过:
<?php echo get_post_meta( $downloads['product_id'], 'simple_title', true ); ?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句