Skip to content

Instantly share code, notes, and snippets.

View Auke1810's full-sized avatar

Auke Jongbloed Auke1810

View GitHub Profile
@Auke1810
Auke1810 / gist:827256dfbea142fbed119b892f463d10
Created February 14, 2019 15:14
Remove multiple characters from feed
/**
* Alter Product feed item
* remove multiple characters from attribute
*/
function alter_feed_description_attribute( $attributes, $feed_id, $product_id ) {
global $product;
// Remove multiple characters from attribute
$remove = [",", ":", ";"];
$attributes['description'] = str_replace($remove, '', $attributes['description']);
@Auke1810
Auke1810 / use-parent-description-for-product-variations.php
Last active July 14, 2020 11:03
Use parent description for product variations. By default the woocommerce product feed manager will use the description from the product variation. This code will make sure you use the parent product description for every product variation.
/**
* Use parent description for product variations
*/
function use_parent_description_for_product_variations( $data, $feed_id, $product_id ) {
$wc_product = wc_get_product( $product_id );
if ( $wc_product && ( $wc_product instanceof WC_Product_Variation || $wc_product instanceof WC_Product_Variable ) ) {
$parent_id = $wc_product->get_parent_id( 'feed' );
$wc_parent = wc_get_product( $parent_id );
@Auke1810
Auke1810 / alter_feed_atribute_description
Last active February 19, 2024 09:45
Create clean description attribute by removing html, VC en DIVI markup etc.
/**
* Create clean description attribute by removing html, VC en DIVI markup etc.
* @param array $attributes variable is an array that contains all the product data that goes into the feed.
* @param Int $feed_id makes it possible to only edit a specific feed. You can find the id of a feed in the url of the Feed Editor
* @param Int $product_id makes it possible to select a specific product id that you want to filter.
* @return array.
*/
function alter_feed_description_item( $attributes, $feed_id, $product_id ) {
// Remove WordPress shortcodes from Description
@Auke1810
Auke1810 / strip_html-description-attribute
Last active April 25, 2022 10:05
remove all html tags from the description tag
<?php
function alter_feed_item( $attributes, $feed_id, $product_id ) {
// Strip html from description attributes
// allow given tags with allowedTags
$allowedTags = "";
$attributes['description'] = strip_tags($attributes['description'], $allowedTags);
// IMPORTANT! Always return the $attributes
@Auke1810
Auke1810 / use_original_description.php
Last active April 6, 2020 08:19
use the original description without stripping away all the line breaks and paragraph tags from the description field.
// use the original description without stripping away all the line breaks and paragraph tags from the description field.
function use_original_description( $data, $feed_id, $product_id ) {
// Only use the original description in the feed with the given ID (in this case 2)
// remove if you want this for all feeds.
if($feed_id == 2 ){
// Get the product.
$wc_product = wc_get_product( $product_id );
@Auke1810
Auke1810 / wppfm_xml_element_attribute
Last active June 10, 2020 11:15
Filternaam: wppfm_xml_element_attribute Drie parameters: attribute_value: dit is de standaard waarde die dus gewijzigd kan worden. Is standaard een empty string. xml_key: dit is de naam van het xml element, dus deze parameter kan worden gebruikt om het gewenste xml element te vinden xml_value: de waarde van het xml element. Dus om een attribute …
Function add_attribute_to_xml_tag( $attribute_value, $xml_key, $xml_value ) {
if ( 'bottles' === $xml_key ) {
return 'size=”750 ml”';
} else {
return $attribute_value;
}
}
add_filter( 'wppfm_xml_element_attribute', 'add_attribute_to_xml_tag', 10, 3 );
@Auke1810
Auke1810 / roundprice.php
Last active March 8, 2022 05:48
In this example we changed the price attribute and rounded the price with the round() function.
<?php
// Round the price
function round_price( $data, $feed_id, $product_id ) {
// round price.
$round_price = round($data['price'], 2);
// Store the rounded price in the feed price element.
$data['price'] = $round_price;
@Auke1810
Auke1810 / shortcodes_unique_identifiers.php
Last active March 9, 2021 09:37
Get GTIN or MPN values from products added to products by our product feed manager and create shortcodes to use on website
<?php
// MPN shortcode function
function wppfm_brand_shortcode() {
// get MPN value.
//$r = get_post_meta( $post->ID, 'wppfm_product_brand', true );
$r = get_post_meta( get_the_ID(), 'wppfm_product_brand', true );
// return MPN
return $r;
@Auke1810
Auke1810 / remove_list_products.php
Created August 26, 2021 08:38
exclude list of products from feed with the use of an array
<?php
function exclude_list_from_feed( $attributes, $feed_id, $product_id ) {
//Array with the numbers from products we want te exclude
$exclude_array = array(13608, 13632, 16123, 16405);
if (in_array($attributes['id'], $exclude_array,) == false )
{
// Return the $attributes from products not in the exclude list
<?php
// Price including or excluding tax
function tax_price( $data, $feed_id, $product_id ) {
global $product, $woocommerce;
// Only add this to the feed with id 58
// change the number to the feed you want to affect the prices.
// OR remove the if statement if you want to affect all feeds
if($feed_id == 1){