如下图所示,我如何在我商店页面上的产品中直接添加下拉菜单

时间:2019-01-29 作者:Mayur Dhole

我目前正在使用WordPress,所以请帮助我如何在商店页面上添加蔬菜质量定价下拉列表,而不是在产品页面上。我有该下拉列表,但它只显示在产品页面上。我想在主页上显示,您可以查看我的网站:-www.nagpurvegies。com公司

1 个回复
SO网友:Zeshan

我猜你在找这个enter image description hereSource : https://iconicwp.com/blog/show-variations-shop-page-woocommerce/

/**
 * Replace add to cart button in the loop.
 */
function iconic_change_loop_add_to_cart() {
    remove_action( \'woocommerce_after_shop_loop_item\', \'woocommerce_template_loop_add_to_cart\', 10 );
    add_action( \'woocommerce_after_shop_loop_item\', \'iconic_template_loop_add_to_cart\', 10 );
}

add_action( \'init\', \'iconic_change_loop_add_to_cart\', 10 );

/**
 * Use single add to cart button for variable products.
 */
function iconic_template_loop_add_to_cart() {
    global $product;

    if ( ! $product->is_type( \'variable\' ) ) {
        woocommerce_template_loop_add_to_cart();
        return;
    }

    remove_action( \'woocommerce_single_variation\', \'woocommerce_single_variation_add_to_cart_button\', 20 );
    add_action( \'woocommerce_single_variation\', \'iconic_loop_variation_add_to_cart_button\', 20 );

    woocommerce_template_single_add_to_cart();
}

/**
 * Customise variable add to cart button for loop.
 *
 * Remove qty selector and simplify.
 */
function iconic_loop_variation_add_to_cart_button() {
    global $product;

    ?>
    <div class="woocommerce-variation-add-to-cart variations_button">
        <button type="submit" class="single_add_to_cart_button button"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
        <input type="hidden" name="add-to-cart" value="<?php echo absint( $product->get_id() ); ?>" />
        <input type="hidden" name="product_id" value="<?php echo absint( $product->get_id() ); ?>" />
        <input type="hidden" name="variation_id" class="variation_id" value="0" />
    </div>
    <?php
}

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register