Documentatie CycleSoftware WooCommerce plugin
Filters & hooks
Filters & hooks
Hieronder staan diverse filters die actief zijn binnen de plugin.
Maximum aantal producten dat wordt geïmporteerd (standaard 2000)
function filter_woocycle_max_import( $limit ) {
return 2000;
}
add_filter( 'woocycle_max_import', 'filter_woocycle_max_import' );
Producten importeren die geen afbeeldingen hebben (standaard true)
function filter_woocycle_import_products_without_images( $bool ) {
return true;
}
add_filter( 'woocycle_import_products_without_images', 'filter_woocycle_import_products_without_images' );
Fietsen importeren (standaard true)
function filter_woocycle_import_bicycle( $bool ) {
return true;
}
add_filter( 'woocycle_import_bicycle', 'filter_woocycle_import_bicycle' );
Artikelen en fietsen importeren (standaard true)
function filter_woocycle_import_products( $bool ) {
return true;
}
add_filter( 'woocycle_import_products', 'filter_woocycle_import_products' );
Product importeren (standaard true)
function filter_woocycle_import_product( $bool, $product_data ) {
return true; // Gebruik false om geen producten te importeren of pas je eigen logica toe d.m.v. de array $product_data
}
add_filter( 'woocycle_import_product', 'filter_woocycle_import_product', 10, 2 );
Afbeeldingen van producten importeren (standaard true)
function filter_woocycle_sync_images( $bool ) {
return true;
}
add_filter( 'woocycle_sync_images', 'filter_woocycle_sync_images' );
Nieuwe bestellingen exporteren naar Cyclesoftware? (standaard true)
function filter_woocycle_export_orders( $bool ) {
return true;
}
add_filter( 'woocycle_export_orders', 'filter_woocycle_export_orders' );
Toegang (capability) tot plugin instellingen
function filter_woocycle_capability( $capability ) {
return 'manage_woocommerce';
}
add_filter( 'woo_cycle_capability', 'filter_woocycle_capability' );
Gewicht importeren leverancier? (standaard true)
function filter_woocycle_sync_weight( $bool ) {
return true;
}
add_filter( 'woocycle_sync_weight', 'filter_woocycle_sync_weight' );
Productattributen aanpassen
/**
Zie hieronder een voorbeeld van een attribute dat wordt gebruikt.
In dit geval wordt een status eigenschap toegevoegd met de waarde "Nieuw".
$attributes['status'] = array(
'name' => 'Status',
'term_names' => array( 'Nieuw' ),
'is_visible' => true,
'for_variation' => false,
);
**/
function filter_woocycle_product_attributes( $attributes, $post_id )
return $attributes;
}
add_filter( 'woocycle_sync_product_attributes', 'filter_woocycle_product_attributes', 10, 2 );
Actions
woocycle_insert_product_before
Zie hieronder
woocycle_insert_product_after
Voorbeeld: Koppel alle elektrische fietsen aan een bepaalde product categorie
/**
* Perform actions after product Cyclesoftware sync
*
* @param $post_id
* @param $product_data
*/
function woocycle_insert_product_after( $post_id, $product_data ) {
$product_taxonomy = 'product_cat';
if( $product_data['is_bicycle'] === true ) {
$terms = array();
if( !empty( $product_data['product_group_sub_sub'] ) && ( stripos( $product_data['product_group_sub_sub'], 'elektrisch' ) !== false ) ) {
$terms[] = 1; // PRODUCT CATEGORIE ID DIE JE WIL TOEWIJZEN AAN ELEKTRISCHE FIETSEN
}
wp_set_object_terms( $post_id, $terms, $product_taxonomy, true );
}
}
add_action( 'woocycle_insert_product_after', 'woocycle_insert_product_after', 10, 2 );
Voorbeeld: Koppel een producteigenschap aan de hand de waarde van het vrije veld 6 in Cyclesoftware
<?php
/**
* Add custom term and attach to product
*
* @param $post_id
* @param $product_data
*/
function woocycle_add_term_from_field( $post_id, $product_data ) {
$product_taxonomy = 'pa_slug'; // Hier de slug van de eigenschap met prefix pa_
if( taxonomy_exists( $product_taxonomy ) ) {
if ( isset( $product_data['custom_variable_1'] ) ) {
wp_set_object_terms( $post_id, [ $product_data['custom_variable_1'] ], $product_taxonomy, true );
}
}
}
add_action( 'woocycle_insert_product_after', 'woocycle_add_term_from_field', 10, 2 );
Plugin aanschaffen?
Kies een abonnementsvorm hieronder
- Onbeperkt aantal producten
- Automatisch dagelijkse productimport
- Actuele voorraadstatus
- Doorplaatsen van bestellingen naar Cyclesoftware