PHP code example of shoppingfeed / shoppingfeed-for-woocommerce
1. Go to this page and download the library: Download shoppingfeed/shoppingfeed-for-woocommerce library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shoppingfeed / shoppingfeed-for-woocommerce example snippets
add_filter( 'shopping_feed_custom_category_taxonomy', 'your_custom_category_function' );
/** @return string */
function your_custom_category_function() {
return 'your_custom_category_slug';
}
add_filter( 'shopping_feed_custom_brand_taxonomy', 'your_custom_brand_function' );
/** @return string */
function your_custom_brand_function() {
return 'your_custom_brand_slug';
}
add_filter( 'shopping_feed_custom_ean', 'your_custom_ean_function' );
/** @return string */
function your_custom_ean_function() {
return 'your_custom_ean_slug';
}
add_filter( 'shopping_feed_products_custom_args', 'your_custom_args_function' );
/** @return array */
function your_custom_args_function() {
//array of args
return array();
}
add_filter( 'shopping_feed_orders_to_import', 'your_custom_statuses_function' );
/** @return array */
function your_custom_statuses_function() {
// array of statuses (strings)
return array();
}
add_filter( 'shopping_feed_tracking_number', 'your_custom_tracking_number_function' );
/** @return string */
function your_custom_tracking_number_function() {
return ‘your_custom_order_meta_key’
}
add_filter( 'shopping_feed_tracking_link', 'your_custom_tracking_url_function' );
/** @return string */
function your_custom_tracking_url_function() {
return ‘your_custom_order_meta_key’
}
add_filter( 'shopping_feed_extra_fields', 'sf_product_extra_fields', 10, 2 );
/**
* Include additional fields for products in product feed.
*
* @param array $fields
* @param \WC_Product $product
*
* @return array
*/
function sf_product_extra_fields( $fields, $product ) {
$fields[] = array(
'name' => 'my_custom_product_field',
'value' => 'my_custom_value',
);
return $fields;
}
add_filter( 'shopping_feed_variation_extra_fields', 'sf_product_variation_extra_fields', 10, 2 );
/**
* Include additional fields for variation in product feed.
*
* @param array $fields
* @param \WC_Product $variation
*
* @return array
*/
function sf_product_variation_extra_fields( $fields, $variation ) {
$fields[] = array(
'name' => 'my_custom_variation_field',
'value' => 'my_custom_value',
);
return $fields;
}
add_filter( 'shopping_feed_variation_main_image', 'your_custom_variation_main_images_function', 10, 3 );
/**
* Use the parent's thumbnail if the variation doesn't have one.
*
* @param string $main_image The main image of the variation.
* @param \WC_Product_Variation $variation The variation.
* @param \WC_Product_Variable $product The product.
*
* @return string
*/
function your_custom_variation_main_images_function( $main_image, $variation, $product ) {
if ( empty( $main_image ) && has_post_thumbnail( $product->get_id() ) ) {
$main_image = get_the_post_thumbnail_url( $product->get_id(), 'full' );
}
return $main_image;
}
add_filter( 'shopping_feed_variation_images', 'your_custom_variation_images_function', 10, 3 );
/**
* @param array $images
* @param WC_Product $wc_product
* @param int $variation_id
*
* @return array
*/
function your_custom_variation_images_function( $images, $wc_product, $variation_id ) {
$images[] = 'https://domain.com/image1.jpg';
$images[] = 'https://domain.com/image2.jpg';
return $images;
}