php 海狸生成器 - WC Arhicve显示缺货标签和按钮

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 海狸生成器 - WC Arhicve显示缺货标签和按钮相关的知识,希望对你有一定的参考价值。

if( class_exists('FLPageData') )
{
 
    add_filter( 'fl_builder_register_settings_form', 'probb_woo_product_grid_settings', 20, 2 );
    function probb_woo_product_grid_settings( $form, $slug ) {
        if ( 'post-grid' != $slug ) {
            return $form;
        }
 
        $form['layout']['sections']['woo']['fields']['woo_stock'] = [
            'type'          => 'select',
            'label'         => __( 'Stock Notifications', 'fl-theme-builder' ),
            'default'       => 'hide',
            'options'       => [
                'show'          => __( 'Show', 'fl-theme-builder' ),
                'hide'          => __( 'Hide', 'fl-theme-builder' ),
            ]
        ];
 
        return $form;
    }
 
    add_action( 'fl_builder_post_grid_before_content', 'probb_post_grid_before_content' );
    /**
     * Adds WooCommerce product stock info before the grid layout content.
     *
     * @since 1.0
     * @param object $settings
     * @return void
     */
    function probb_post_grid_before_content( $settings )
    {
        global $product;
 
        // Bail if no product
        if ( ! $product ) {
            return;
        }
 
        // Product stock notice
        if ( 'show' == $settings->woo_stock ) {
            echo FLPageData::get_value( 'post', 'woocommerce_product_stock_notice' );
        }
    }
 
    /**
     * Product stock notice
     */
    FLPageData::add_post_property( 'woocommerce_product_stock_notice', array(
        'label'   => __( 'Product Stock Notice', 'fl-theme-builder' ),
        'group'   => 'woocommerce',
        'type'    => 'html',
        'getter'  => 'get_product_stock_notice',
    ) );
 
    /**
     * Echo the stock notice at front end
     */
    function get_product_stock_notice()
    {
        global $product;
 
        $html = '';
        $availability = $product->get_availability();
 
        if ( ! empty( $availability['class'] ) && ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) ) {
            ob_start();
 
            if ( $product->is_in_stock() ) {
                $stock_html = __( 'In stock', 'woocommerce' );
            } else {
                $stock_html = __( 'Out of stock', 'woocommerce' );
            }
 
            wc_get_template( 'single-product/stock.php', array(
                'product'      => $product,
                'class'        => $availability['class'] . ' stock_status',
                'availability' => $stock_html,
            ) );
 
            $html = ob_get_clean();
 
            echo apply_filters( 'woocommerce_get_stock_html', $html, $product );
        }
 
        return;
    }
}

以上是关于php 海狸生成器 - WC Arhicve显示缺货标签和按钮的主要内容,如果未能解决你的问题,请参考以下文章

php 海狸生成器形状下拉列表的SVG形状

php 删除海狸生成器的'go to top'标记并使用我自己的标记进行修改。

text 海狸生成器 - FIS

html 海狸生成器主题页面HTML

css 海狸生成器按钮覆盖

css 海狸生成器全宽