php - How do at make my standalone file woocommerce ready so I can use the functions
问题描述
Hi I am having a problem getting my standalone file to use woocommerce functions. may make it work when I hook, but will need to retrieve it for themselves. So I can use the file to jQuery.load (URL) So I come up with that function when the page finishes loading.
Is it possible? Or is that not possible?
My jQuery call for file:
jQuery( document ).ready(function() {
jQuery('div#result').load('http://localhost/(hidden)/wp-content/themes/storefront-child/variation_product_site.php');
});
My standalone file
<?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 the_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>
function add_woocommerce_file() {
echo '<div id="result"></div>';
}
add_filter('woocommerce_after_shop_loop_item', 'add_woocommerce_file', 60);
Fatal error: Uncaught Error: Call to a member function get_available_variations() on null in C:\www(Hidden)\wp-content\plugins\variation-product-site\variation_product_site.php on line 9
解决方案
推荐阅读
- c# - SqlBulkCopy 防止在关系表中插入为空或不为空的数据
- python - python代码中的哪个部分出现语法错误?
- sas - SAS从csv加载数据时如何将字符串转换为时间?
- python - 使用 pymysql 和 Mysql Aurora DB 返回 json
- typescript - 打字稿泛型使用函数参数作为可选
- php - 无法从发送方和接收方的数据库服务器打印 chat_message 数据
- ios - googleCast 框架的本地化不起作用
- java - AsyncTask 线程如何与主线程通信?
- python - 给定组=1,大小为 16 16 3 3 的权重,预期输入 [16、64、222、222] 有 16 个通道,但有 64 个通道?
- java - Java 正则表达式不区分大小写与德语变音符号