WooCommerce额外产品选项

时间:2015-03-26 12:22:36

标签: php wordpress woocommerce

任何人请帮我找到以下解决方案:

  • 我想在woocommerce电子邮件模板上显示特定的产品选项价值。

显示所有选项值的代码:

public function tm_woocommerce_email_after_row($item_id, $item, $order , $flat=false){
    $html = '';
    $has_epo = isset($item['item_meta']) && isset($item['item_meta']['_tmcartepo_data']) && isset($item['item_meta']['_tmcartepo_data'][0]);
    if ($has_epo){
        $epos = maybe_unserialize($item['item_meta']['_tmcartepo_data'][0]);

        $current_product_id=$item['product_id'];
        $original_product_id = floatval(TM_EPO_WPML()->get_original_id( $current_product_id,'product' ));
        if (TM_EPO_WPML()->get_lang()==TM_EPO_WPML()->get_default_lang() && $original_product_id!=$current_product_id){
            $current_product_id = $original_product_id;
        }
        $wpml_translation_by_id=$this->get_wpml_translation_by_id( $current_product_id );

        foreach ($epos as $key => $epo) {
            if ($epo){
                if(!isset($epo['quantity'])){
                    $epo['quantity'] = 1;
                }
                if(isset($wpml_translation_by_id[$epo['section']])){
                    $epo['name'] = $wpml_translation_by_id[$epo['section']];
                }
                if(!empty($epo['multiple']) && !empty($epo['key'])){
                    $pos = strrpos($epo['key'], '_');
                    if($pos!==false) {
                        $av=array_values( $wpml_translation_by_id["options_".$epo['section']] );
                        if (isset($av[substr($epo['key'], $pos+1)])){
                            $epo['value'] = $av[substr($epo['key'], $pos+1)];
                        }
                    }
                }
                if ($flat){
                    $html .= "\n" . $epo['name'] . ' : ' . $epo['value'];
                    $html .= "\n" . sprintf( __( 'Quantity: %s', 'woocommerce' ), ( $epo['quantity'] * (float) $item['item_meta']['_qty'][0] ) );
                    if (!empty($item['item_meta']['tm_has_dpd'])){
                    }else{                          
                        $html .= "\n" . sprintf( __( 'Cost: %s', 'woocommerce' ), (wc_price( (float) $epo['quantity'] * (float) $epo['price'] * (float) $item['item_meta']['_qty'][0] )) );
                    }
                }else{
                    $html .= '';
                    $html .= ''.$epo['name'].': '.$epo['value'].'<br/>';
                    $html .= '';
                }
            }
        }

    }

    echo $html;     
}

我使用此插件作为额外选项: WooCommerce Extra Product Options

任何提示都将非常感激。 非常感谢你!

0 个答案:

没有答案