Woocommerce 如何更改延期交货按钮的操作?

问题描述 投票:0回答:1

如何让点击预订按钮时调用 Formcraft 联系表单? (仅限预购产品)谢谢!

不幸的是,我没有在 wordpress CODEX 中找到任何关于如何通过functions.php影响“添加到购物车”按钮以仅更改缺货产品的按钮链接的信息。

php wordpress function woocommerce e-commerce
1个回答
0
投票

请检查此代码

add_filter('woocommerce_loop_add_to_cart_link', 'custom_pre_order_button', 10, 2);
add_filter('woocommerce_single_product_summary', 'custom_pre_order_button_single', 30);

function custom_pre_order_button($button, $product) {
    if ($product->is_on_backorder()) {
        $button = '<a href="#" class="button pre-order-button" onclick="openFormcraftForm()">Pre-order Now</a>';
    }
    return $button;
}

function custom_pre_order_button_single() {
    global $product;

    if ($product->is_on_backorder()) {
        remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
        echo '<a href="#" class="button pre-order-button" onclick="openFormcraftForm()">Pre-order Now</a>';
    }
}

function openFormcraftForm() {
    ?>
    <script type="text/javascript">
        function openFormcraftForm() {
            jQuery('#formcraft-form-id').trigger('click');
        }
    </script>
    <?php
}
© www.soinside.com 2019 - 2024. All rights reserved.