如何在sprintf中添加woocommerce自定义字段短代码?

时间:2015-11-22 14:28:16

标签: php wordpress wordpress-plugin woocommerce

我想在购物车产品名称中添加自定义字段短代码。现在,我不知道如何显示自定义字段值,因为代码在sprintf中。

我在woocommerce产品中创建了一个自定义字段。海关领域被称为颜色。我希望购物车产品名称打印出自定义字段值。

自定义字段短代码

   <?php echo get_post_meta( get_the_ID(), 'color', true ); ?>

购物车产品名称

                        <?php
                            if ( ! $_product->is_visible() ) {
                                echo apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key ) . '&nbsp;';
                            } else {
                                echo apply_filters( 'woocommerce_cart_item_name', sprintf( '<a class="items-info" href="%s">%s </a>', esc_url( $_product->get_permalink( $cart_item ) ), $_product->get_title() ), $cart_item, $cart_item_key );
                            }

                        ?>

例如,

我的产品名称是“New york tee”,我的自定义字段颜色值为“white” 我希望它在我的woocommerce购物车产品名称中显示为“New york tee - white”。另外,我想在产品名称和自定义字段值之前添加一个破折号。里 “纽约三通 - 白色” 有人能帮我吗?谢谢。

1 个答案:

答案 0 :(得分:0)

您可以在--- 0: System.Management.Automation.ErrorRecord ------------------------ writeErrorStream : True Exception : System.Management.Automation.RemoteException: warning:00000000000000000000000000000000000000000 00000000000000000000000000000 TargetObject : warning:0000000000000000000000000000000000000000000000000000000000000000000000 CategoryInfo : NotSpecified: (warning:0000000...000000000000000:String) [], RemoteException FullyQualifiedErrorId : NativeCommandError ErrorDetails : InvocationInfo : System.Management.Automation.InvocationInfo PipelineIterationInfo : {0, 0, 0} PSMessageDetails : --- 1: System.Management.Automation.ErrorRecord ------------------------ writeErrorStream : True Exception : System.Management.Automation.RemoteException: warning:00000000000000000000000000000000000000000 00000000000000000000000000001 warning:0000000000000000000000000000000000000000000000000000000000000000000002 warning:0000000000000000000000000000000000000000000000000000000000000000000003 warning:0000000000000000000000000000000000000000000000000000000000000000000004 warning:0000000000000000000000000000000000000000000000000000000000000000000005 warning:0000000000000000000000000000000000000000000000000000000000000000000006 warning:0000000000000000000000000000000000000000000000000000000000000000000007 warning:0000000000000000000000000000000000000000000000000000000000000000000008 warning:0000000000000000000000000000000000000000000000000000000000000000000009 warning:0000000000000000000000000000000000000000000000000000000000000000000010 warning:0000000000000000000000000000000000000000000000000000000000000000000011 warning:0000000000000000000000000000000000000000000000000000000000000000000012 warning:0000000000000000000000000000000000000000000000000000000000000000000013 warning:0000000000000000000000000000000000000000000000000000000000000000000014 warning:0000000000000000000000000000000000000000000000000000000000000000000015 warning:0000000000000000000000000000000000000000000000000000000000000000000016 warning:0000000000000000000000000000000000000000000000000000000000000000000017 warning:0000000000000000000000000000000000000000000000000000000000000000000018 warning:0000000000000000000000000000000000000000000000000000000000000000000019 warning:0000000000000000000000000000000000000000000000000000000000000000000020 warning:0000000000000000000000000000000000000000000000000000000000000000000021 warning:0000000000000000000000000000000000000000000000000000000000000000000022 warning:0000000000000000000000000000000000000000000000000000000000000000000023 warning:0000000000000000000000000000000000000000000000000000000000000000000024 warning:0000000000000000000000000000000000000000000000000000000000000000000025 warning:0000000000000000000000000000000000000000000000000000000000000000000026 warning:0000000000000000000000000000000000000000000000000000000000000000000027 warning:0000000000000000000000000000000000000000000000000000000000000000000028 warning:0000000000000000000000000000000000000000000000000000000000000000000029 warning:0000000000000000000000000000000000000000000000000000000000000000000030 warning:0000000000000000000000000000000000000000000000000000000000000000000031 warning:0000000000000000000000000000000000000000000000000000000000000000000032 warning:0000000000000000000000000000000000000000000000000000000000000000000033 warning:0000000000000000000000000000000000000000000000000000000000000000000034 warning:0000000000000000000000000000000000000000000000000000000000000000000035 warning:0000000000000000000000000000000000000000000000000000000000000000000036 warning:0000000000000000000000000000000000000000000000000000000000000000000037 warning:0000000000000000000000000000000000000000000000000000000000000000000038 warning:0000000000000000000000000000000000000000000000000000000000000000000039 warning:0000000000000000000000000000000000000000000000000000000000000000000040 warning:0000000000000000000000000000000000000000000000000000000000000000000041 warning:0000000000000000000000000000000000000000000000000000000000000000000042 warning:0000000000000000000000000000000000000000000000000000000000000000000043 warning:0000000000000000000000000000000000000000000000000000000000000000000044 warning:0000000000000000000000000000000000000000000000000000000000000000000045 warning:0000000000000000000000000000000000000000000000000000000000000000000046 warning:0000000000000000000000000000000000000000000000000000000000000000000047 warning:0000000000000000000000000000000000000000000000000000000000000000000048 warning:0000000000000000000000000000000000000000000000000000000000000000000049 warning:0000000000000000000000000000000000000000000000000000000000000000000050 warning:00000000000000000000000000000000000000000000000000000000000 TargetObject : CategoryInfo : NotSpecified: (:) [], RemoteException FullyQualifiedErrorId : NativeCommandErrorMessage ErrorDetails : InvocationInfo : System.Management.Automation.InvocationInfo PipelineIterationInfo : {0, 0, 1} PSMessageDetails : --- 2: System.Management.Automation.ErrorRecord ------------------------ writeErrorStream : True Exception : System.Management.Automation.RemoteException: 00000000051 warning:0000000000000000000000000000000000000000000000000000000000000000000052 warning:0000000000000000000000000000000000000000000000000000000000000000000053 warning:0000000000000000000000000000000000000000000000000000000000000000000054 warning:0000000000000000000000000000000000000000000000000000000000000000000055 warning:0000000000000000000000000000000000000000000000000000000000000000000056 warning:0000000000000000000000000000000000000000000000000000000000000000000057 warning:0000000000000000000000000000000000000000000000000000000000000000000058 warning:0000000000000000000000000000000000000000000000000000000000000000000059 warning:0000000000000000000000000000000000000000000000000000000000000000000060 warning:0000000000000000000000000000000000000000000000000000000000000000000061 warning:0000000000000000000000000000000000000000000000000000000000000000000062 warning:0000000000000000000000000000000000000000000000000000000000000000000063 warning:0000000000000000000000000000000000000000000000000000000000000000000064 warning:0000000000000000000000000000000000000000000000000000000000000000000065 warning:0000000000000000000000000000000000000000000000000000000000000000000066 warning:0000000000000000000000000000000000000000000000000000000000000000000067 warning:0000000000000000000000000000000000000000000000000000000000000000000068 warning:0000000000000000000000000000000000000000000000000000000000000000000069 TargetObject : CategoryInfo : NotSpecified: (:) [], RemoteException FullyQualifiedErrorId : NativeCommandErrorMessage ErrorDetails : InvocationInfo : System.Management.Automation.InvocationInfo PipelineIterationInfo : {0, 0, 2} PSMessageDetails : 上添加过滤器以修改标题

woocommerce_cart_item_name