在 WooCommerce 中,我尝试为特定产品类别的购物车商品设置最低数量。
根据“ WooCommerce 中特定产品类别的最小购物车商品数量”,这是我的代码尝试:
add_action( 'woocommerce_check_cart_items', 'wc_min_item_required_qty' );
function wc_min_item_required_qty() {
$category = 'games'; // The targeted product category
$min_item_qty = 4; // Minimum Qty required (for each item)
$display_error = false; // Initializing
// Loop through cart items
foreach(WC()->cart->get_cart() as $cart_item ) {
$item_quantity = $cart_item['quantity']; // Cart item quantity
$product_id = $cart_item['product_id']; // The product ID
// For cart items remaining to "Noten" producct category
if( has_term( $category, 'product_cat', $product_id ) && $item_quantity < $min_item_qty …Run Code Online (Sandbox Code Playgroud) 我正在尝试在一个迁移文件中迁移特定行。
例:
之前:
Schema::create('categories', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('category_name');
$table->integer('parent_id')->nullable();
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
后:
Schema::create('categories', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('category_name');
$table->string('img_url'); // ? new column
$table->integer('parent_id')->nullable();
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
现在我只想迁移该行: $table->string('img_url');
可能吗?
所以我使用 axios 从 url 获取 api
这是我的代码:
<html>
<head>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="{{asset("/core/vue.js")}}" type="text/javascript"></script>
</head>
<body>
<div id="app">
@{{ info }}
<button v-on:click.prevent="GetId($event)" value="1">click me!</button>
</div>
<style>
</style>
<script type="text/javascript" language="JavaScript">
new Vue({
el: '#app',
data: {
info: null,
value: null
},
methods:{
GetId:function (event) {
element = event.currentTarget;
value = element.getAttribute('value');
axios
.get('/api/GetProduct/'+value)
.then(response => (this.info = response))
.then(this.value = value)
.catch(error => console.log(error))
}
},
})
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但问题是我得到了一个长数组,我只需要数据从中。
我尝试使用response.$data但在这里不起作用是我得到的响应:
{ "data": { …Run Code Online (Sandbox Code Playgroud)