Gists

by mgibbs189 - 2 months ago

<?php

add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'el-z9v5wp' == $item['settings']['name'] ) {
        $shortcode = '[awts-total-sales product_id="' . $value . '" include_setting="true"]';
        $value = do_shortcode( $shortcode );
    }
    return $value;
}, 10, 2 );
by mgibbs189 - 3 months ago

<?php

add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'actu-date' == $item['settings']['name'] ) {
        $find = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Opt', 'Nov', 'Dec' ];
        $replace = [ 'janv', 'févr', 'mars', 'avril', 'mai', 'juin', 'juil', 'août', 'sept', 'oct', 'nov', 'déc' ];
        return str_replace( $find, $replace, $value );
    }
    return $value;
}, 10, 2 );
by mgibbs189 - 4 months ago

<?php

add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'phone-colors' == $item['settings']['name'] ) {
        if ( is_array( $value ) ) {
        	$temp = '<style>.color-square { display: inline-block; width: 20px; height: 20px; border: 1px solid #000; border-radius: 50%; margin-right:5px; }</style>';
        	$value = wp_list_pluck( $value, 'color' );
        	foreach ( $value as $val ) {
        		$temp .= '<div class="color-square" style="background-color:' . $val . '"></div>';
        	}
        	$value = $temp;
        }
    }
    return $value;
}, 10, 2 );

by mgibbs189 - 5 months ago

<?php

// Add the following into the custom-hooks.php file

add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    global $post;

    if ( 'attachment' == $item['settings']['name'] ) {
        $value = wp_get_attachment_image( $post->ID );
    }
    return $value;
}, 10, 2 );
by mgibbs189 - 7 months ago

<?php

// Add the following to custom-hooks.php or into your (child) theme's functions.php

add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'add-to-cart' == $item['settings']['name'] ) {
        global $post;
        $value = do_shortcode( '[add_to_cart id="' . $post->ID . '"]' );
    }
    return $value;
}, 10, 2 );

by djrmom - 9 months ago

<?php
/** output comments in layout builder
 ** add a placeholder (Post ID is a good choice) to layout builder and name it comment-output
 ** replace the value with the filter below
 ** to change the template file for the output if you need it different comments on
 ** single posts, copy comments.php to a new file (ie - comments-builder.php)
 ** and include the file name in the function - comments_template( '/comments-builder.php' );
 **/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'comment-output' == $item['settings']['name'] ) {		
      global $withcomments;
      $withcomments = "1";
      ob_start();
      if ( comments_open() || get_comments_number() ) {
        comments_template();
      }
      $value = ob_get_clean();
    }
    return $value;
}, 10, 2 );

by djrmom - 10 months ago

<?php

/** replace feature image in layout builder with woocommerce html for image + sale icon/banner
 ** additional css styles will likely need to be added to replicate the styles used by woocommerce **/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'featured_image' == $item['source'] && 'product' == get_post_type( get_the_id() ) ) {
        $product = wc_get_product( get_the_ID() );
        ob_start();
        woocommerce_template_loop_product_link_open();
        woocommerce_show_product_loop_sale_flash();
        woocommerce_template_loop_product_thumbnail();
        woocommerce_template_loop_product_link_close();
        $value = ob_get_clean();
    }
	return $value;
}, 10, 2 );

/** adding the woocomerce class to your page may help apply existing styles for sale and image **/
add_filter( 'body_class', function( $classes ) {
    if ( is_page( 'a-product-shortcode-test' ) ) {
        $classes[] = 'woocommerce';
        return $classes;
    }
});

/** the default woocommerce styles use absolute positioning, this is an example that can be modified
 ** to fit your design **/
add_action( 'wp_head', function() { ?>
    <style>
    .woocommerce .fwpl-item {
        position: relative;
    }
    .woocommerce .fwpl-item .onsale {
        top: 0;
        right: 0;
        left: auto;
        margin: -.5em -.5em 0 0;
    }
    </style>
<?php });
by djrmom - 10 months ago

<?php

/** replace woocommerce "price" in layout builder with price/sale price html **/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'woo/price' == $item['source'] ) {
        $product = wc_get_product( get_the_ID() );
        $value = $product->get_price_html();
    }
	return $value;
}, 10, 2 );
by djrmom - 11 months ago

<?php
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'el-ymud8n' == $item['settings']['name'] ) {
        $value = date_create( $value );
        $value = date_format( $value, "d-m-Y" );
    }
    return $value;
}, 10, 2 );
by djrmom - 11 months ago

<?php

/** outputs woocommerce rating as stars in layout builder **/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'woo/average_rating' == $item['source'] ) { // replace some_field with your item source

        $product = wc_get_product( get_the_ID() );

        $rating_count = $product->get_rating_count();
        $average      = $product->get_average_rating();

        $value =  '<div class="woocommerce-product-rating">' . wc_get_rating_html( $average, $rating_count ) . '</div>';
    }
    return $value;
}, 10, 2 );