如何在Woocommerce中基于产品类型动态显示“再次订购”按钮

时间:2018-09-10 22:32:56

标签: woocommerce

早安, 请我根据每个产品类型(简单,变量,分组,外部)动态显示“再次订购”按钮。组合不同来源后,我已经能够做到这一点;

constant SAMPLE_T_MAX : integer := 2**(sample_t'length-1)-1;

max_sample <= to_signed(SAMPLE_T_MAX, max_sample'length);

但是在我这样做之后,它根本不显示按钮,我不确定发生了什么。我也很想知道如何全局获取订单的产品类型,因为我将使用更多的<?php /** * Order again button * * This template can be overridden by copying it to yourtheme/woocommerce/order/order-again.php. * * HOWEVER, on occasion WooCommerce will need to update template files and you * (the theme developer) will need to copy the new files to your theme to * maintain compatibility. We try to do this as little as possible, but it does * happen. When this occurs the version of the template file will be bumped and * the readme will list any important changes. * * @see https://docs.woocommerce.com/document/template-structure/ * @author WooThemes * @package WooCommerce/Templates * @version 2.3.0 */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } ?> <?php function add_order_again_btn( $order ) { $order = new WC_Order( $order_id ); foreach ( $order->get_items() as $item ) { // Get an instance of the WC_Product Object from the WC_Order_Item_Product $product = $item->get_product(); if( $product->is_type('simple') && is_virtual() == true ){ return ?> <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'order_again', $order->get_id() ) , 'woocommerce-order_again' ) ); ?>" class="button"><?php _e( 'Topup again', 'woocommerce' ); ?></a> <?php ; } elseif( !$product->is_type('lottery') ) { return ?> <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'order_again', $order->get_id() ) , 'woocommerce-order_again' ) ); ?>" class="button"><?php _e( 'Bid Again', 'woocommerce' ); ?></a> <?php ; } else { return ?> <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'order_again', $order->get_id() ) , 'woocommerce-order_again' ) ); ?>" class="button"><?php _e( 'Order Again', 'woocommerce' ); ?></a> <?php ; } break; // We stop the loop and keep the first item } } add_shortcode('dyn-order-again-btn', 'izzycart_add_order_again_btn'); ?> <p class="order-again"> <?php do_shortcode('[dyn-order-again-btn]'); ?> </p> ,以便在显示简单产品或任何其他产品类型时可以显示一些内容。

0 个答案:

没有答案