Woocommerce og ny ekstern fil
HejJeg har nogle problemer med at få integreret funktionerne fra woocommerce i min fil som jeg skal bruge.
Her er min kode:
<?php
global $product, $post;
$variations = $product->get_available_variations();
?>
<form class="cart variation" action="" method="post" enctype='multipart/form-data'>
<div class="popup">
<div class="popup-content">
<div class="close-content-container">X</div>
<?php woocommerce_content(); ?>
</div>
</div>
<?php
$output = '
<select name="variation_id" id="variation_id">
<option value="">Vælg...</option>';
foreach( $variations as $variation ){
if($variation['max_qty'] > 0) {//Finder ud af om der er vare på lager det den kalde variation.
$option_value = array();
foreach( $variation['attributes'] as $attribute => $term_slug ){
$taxonomy = str_replace( 'attribute_', '', $attribute );
$attribute_name = get_taxonomy( $taxonomy )->labels->singular_name; // Attribute name
$term_name = get_term_by( 'slug', $term_slug, $taxonomy )->name; // Attribute value term name
$option_value[] = ' ' .$term_name. ' ';
}
$option_value = implode( ' :: ', $option_value );
$output .= '
<option class="option_value" value="'.$variation['variation_id'].'">'.$option_value.'</option>';
}
}
$output .= '
</select>';
?><a type="button" id="open" class="open-popup">Kort varebeskrivelse</a><?php
echo $output;
?>
<input type="hidden" name="variation_id" id="variation_id" value="" />
<input type="hidden" name="product_id" value="<?php echo esc_attr( $post->ID ); ?>" />
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $post->ID ); ?>" />
<div class="tilfoej"><div class="cart_flex">Læg i kurv</div></div>
</form>
<?php
Får fejlen:
Error: Call to a member function get_available_variations() on null in C:\wamp64\www\teenstyle_live\wp-content\themes\storefront-child\
Håber i kan hjælpe mig.
Med venlig hilsen
Morten